http caching

Can you give me any guidance around modifying Zenphoto's browser caching of images?

We have a javascript front end to Zenphoto that allows users to view previously downloaded albums and images without an internet connection (we have an ajax call to download the albums in JSON, and it stores those in browser local storage). The issue: we don't have great control yet over the browser's caching of images.

Zenphoto does send an etag, which is great... but that still forces the browser to check whether the image is modified each request.

Our best case scenario is to get zenphoto to cache images on the browser permanently by sending a far-future expires header, and change the image's URL when the image is modified (say with a timestamp). Example header:
Cache-Control: public, max-age: 315360000 // one year in seconds

Failing that, we'd like to tell browsers not to check for a new version of an image for a few days, like this:
Cache-Control: public, max-age: 86400 // one day in seconds

The second one we can probably do by creating an extension that uses zp_register_filter. We figure out if the request is for an image and send the Cache-Control header.

So: any ideas on doing #1? Is there a better way to do #2?

Thanks!

Comments

  • acrylian Administrator, Developer
    As you probably know Zenphoto is file system based so the check filesystem vs db storage is important to get any changes.

    Headers are sent actually either via theme page requests, the image processor (does above checking) or via the full image access if that is protected as far as I can see at the moment (headers were not my resort in earlier days). Also there is no definition of the Etag at all.

    You could use the `theme_headers` filter to change/add to headers of theme pages but for images itself there is nothing available.
Sign In or Register to comment.