Custom webserver caching

Posted by Mark Kinsella on Stack Overflow See other posts from Stack Overflow or by Mark Kinsella
Published on 2010-02-26T22:05:39Z Indexed on 2010/04/30 6:47 UTC
Read the original article Hit count: 306

I'm working with a custom webserver on an embedded system and having some problems correctly setting my HTTP Headers for caching.

Our webserver is generating all dynamic content as XML and we're using semi-static XSL files to display it with some dynamic JSON requests thrown in for good measure along with semi-static images. I say "semi-static" because the problems occur when we need to do a firmware update which might change the XSL and image files.

Here's what needs to be done: cache the XSL and image files and do not cache the XML and JSON responses. I have full control over the HTTP response and am currently:

  1. Using ETags with the XSL and image files, using the modified time and size to generate the ETag
  2. Setting Cache-Control: no-cache on the XML and JSON responses

As I said, everything works dandy until a firmware update when the XSL and image files are sometimes cached. I've seen it work fine with the latest versions of Firefox and Safari but have had some problems with IE.

I know one solution to this problem would be simply rename the XSL and image files after each version (eg. logo-v1.1.png, logo-v1.2.png) and set the Expires header to a date in the future but this would be difficult with the XSL files and I'd like to avoid this.

Note: There is a clock on the unit but requires the user to set it and might not be 100% reliable which is what might be causing my caching issues when using ETags.

What's the best practice that I should employ? I'd like to avoid as many webserver requests as possible but invalidating old XSL and image files after a software update is the #1 priority.

© Stack Overflow or respective owner

Related posts about http

Related posts about http-header-fields