I've run into a problem where I make changes to a few JavaScript files that are referenced in an HTML file, but the browser doesn't see the changes. It holds onto the copy cached in the browser, even though the web server has a newer version.
Not until I force the browser to clear the cache do I see the changes.
Is this a web-server configuration? Do I need to set my JavaScript files to never cache? I've seen some interesting techniques in the Google Web Toolkit where they actually create a new JavaScript file name any time an update is made. I believe this is to prevent proxies and browsers from keeping old versions of the JavaScript files with the same names.
Is there a list of best practices somewhere?
We append a product build number to the end of all Javascript (and CSS etc.) like so:
Browsers ignore everything after the question mark but upgrades cause a new URL which means cache-reload.
This has the additional benefit that you can set HTTP headers that mean "never cache!"
@Darren The caching problem has occurred on both IIS 6 & Apache 2 out-of-the-box. I'm not sure if the proper resolution is to modify the HTTP response headers, but instead to take the renaming route described in a few of the responses here.
@Chris Good tip. I thought the query string approach was a good one, but it sounds like a unique file or directory name is necessary to cover all cases.
This is probably because the HTTP Expires / Cache-Control headers are set.
http://developer.yahoo.com/performance/rules.html#expires
I wrote about this here:
http://www.codinghorror.com/blog/archives/000932.html
I've written a blog post about how we overcame this problem here:
Avoiding JavaScript and CSS Stylesheet Caching Problems in ASP.NET
Basically, during development you can add a random number to a query string after the filename of your CSS file. When you do a release build, the code switches to using your assembly's revision number instead. This means that in your production environment, your clients can cache the stylesheet, but whenever you release a new version of the site they'll be forced to re-load the file.