Post-Image

Resolve caching issues without additional ?v=versionnumber parameter

Posted on

Have you ever had the need to resolve caching issues for other clients? And did you do that by adding some parameter to your resource link?

The problem with this method is, that proxy’s normaly won’t cache files with a parameter and you won’t get the advantages of caching if a user is visiting your site via a proxy.

With this little code snippet which was copied from the initializr template you can reset the cache of a file by renaming the link to filename.1.jpg for a image.

<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp)$ $1.$3 [L]
</IfModule>

If you want to go one step further you can even automate the image naming by using the latest time when the file was change with a php function. http://www.particletree.com/notebook/automatically-version-your-css-and-javascript-files/

Source: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

Leave a Reply