Javascript versioning to avoid caching, difference in these practices?

Using an updated querystring is a bad solution. See what Steve souders has so say about it: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

The ideal method is to rename the file itself. Some people prefer using the time stamp of the last modification date, which i think is a problem.

In modern web development you really need to optimize your page as much as possible, which means combining css and javascript into single files which are minfied. That means that you introduce a build step into your process, and that the last modification time of your file always will be at your last build. If you set that as your file name, you essentially bust the users cache all the time, and some times you dont need to.

I recommend renaming the files to an md5 sum of their content. That way you can do new builds all the time, but the file name only changes if the content changes. This makes your file name an identifier of the content. Using this you can set a far future expires header on all your static content and simply stop worrying about it any more.

I can recommend using a build system for this, since this workflow gets boring fast. My company open sourced one a while ago that does this among a lot of other things that optimize your web page: https://github.com/One-com/assetgraph-builder There are many other build tools that do the same. Take a look around and find the one that best suits your development setup.

Leave a Comment