26 May 2009
To avoid having to clear the browser cache and force the browser to load CSS and
site.js?ts=115421 instead of
This will cause the browser interpret the URL as a new file, which makes it load the uncached file each time the page is loaded. Problem solved! :)
However, this is a solution that should not be used when the site goes live.
When going live
The approach above is suitable for development, since bandwidth is no issue when developing. However, browser caching is there for a reason - to reduce bandwidth and reduce load times. We don’t want our visitors to download all script and css files every time they reload a certain page.
To force all users to load script file updates, you could rename the file. Still, a more convenient alternative is to simply…add a timestamp to the file path. A word of warning though - when in production, only update the timestamp when a file has actually changed. As soon as you upload a new version of the js or css file, update its timestamp.