Skip to content Skip to sidebar Skip to footer

How Can I Prevent Javascript Caching? Querystring Approach Isn't Working

I've seen other approaches that attach a version number or MD5 hash to a JS src querystring. e.g. However, my JavaScript is still g

Solution 1:

I added log messages and determined that the querystring method is working. Sorry for the unnecessary question.

However, in researching, I found some important points worth mentioning:

  1. One of the articles suggests using a querystring with the current time appended. You probably don't want to follow this suggestion as your files will never be cached. Using source control version numbers or an MD5 hash would be better.
  2. Steve Souders (of High Performance Web Sites fame) notes that certain web proxies never cache anything with a querystring. Thus, the version number should be embedded within the path to the file in order to ensure that your files are cached appropriately when accessed through these proxies. ( http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ )

Solution 2:

It will be cached always. Although, by using a version number (or any other varying string) a new version will be downloaded and used every time, ignoring the previous one.

http://thecrmgrid.wordpress.com/2007/10/22/prevent-caching-of-javascript-include-files-during-development/

http://davidwalsh.name/prevent-cache

Solution 3:

1.)make sure the response headers for the javascript files are correct and include expires, cache-control, etc.

2.)you probably have to append the version not as a query parameter but part of the filename, e.g. page_v.2.js. You could change the javascript filenames at build time for example if you are using Java. That is what i have done.

Post a Comment for "How Can I Prevent Javascript Caching? Querystring Approach Isn't Working"