Optimal Caching Strategies Gotcha

In: Uncategorized

17 Jun 2010

The fastest download is no download, so I was trying to prevent even the 304s (last modified requests & responses) on a recent project. It had been a while since I had to configure Apache for this, but here was the start of a .htaccess file:


<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresActive On
ExpiresDefault "access plus 10 years"
</FilesMatch>

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Header unset ETag
FileETag None
Header unset Last-Modified

I set up a versioning system on the backend so that whenever resources are updated new version numbers are automatically generated to create new request URLs. Thus, I could set far future expires tags. However, it didn’t seem to be working. I kept seeing the requests in fiddler even though the Expires header was set and the Last-Modified header removed. The problem? I was hitting refresh which was causing the clients (FF & Chrome) to request the resources regardless of the headers. Navigating away and then back generated the expected behavior. :p