As I’m sure we’re not the first ones to deal with this, I figured I would throw it out to the community. How are you ensuring clients update their cache when you update your code? If you’re using the method described above, are you using a process that simplifies the change?
As far as I know a common solution is to add a
?<version> to the script’s src link.
I assume at this point that there isn’t a better way than find-replace to increment these “version numbers” in all of the script tags?
You might have a version control system do that for you? Most version control systems have a way to automatically inject the revision number on check-in for instance.
It would look something like this:
Of course, there are always better solutions like this one.
For example, to force the file to be cached for no longer than 1 day, you would send:
Cache-Control: max-age=86400, must-revalidate
For beta, if you want to force the user to always get the latest, you would use:
Cache-Control: no-cache, must-revalidate
Google Page-Speed: Don’t include a query string in the URL for static resources.
Most proxies, most notably Squid up through version 3.0, do not cache resources with a “?” in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.
In this case, you can include the version into URL ex: http://abc.com/v1.2/script.js and use apache mod_rewrite to redirect the link to http://abc.com/script.js. When you change the version, client browser will update the new file.
This usage has been deprected:
CACHE MANIFEST # Aug 14, 2014 /mycode.js NETWORK: *
and generate this file with a new time stamp every time you want users to update their cache. As a side note, if you add this, the browser will not reload (even when a user refreshes the page) until the manifest tells it to.
How about adding the filesize as a load parameter?
So every time you update the file the “filever” parameter changes.
How about when you update the file and your update results in the same file size? what are the odds?
Not all browsers cache files with ‘?’ in it. What I did to make sure it was cached as much as possible, I included the version in the filename.
So instead of
stuff.js?123, I did
mod_redirect(I think) in apache to to
have stuff_*.js to go