views:

53

answers:

3

Hi.

I have a quite troublesome issue which I didn't find a good solution for yet.

I allow caching of all my application static files (JS, CSS and images) by browser for performance.

Problem is, when I'm doing upgrades, the users still use the old version from their cache, which often breaks the application, and requires clearing the cache every time to solve the problem.

Is there any good multi-browser approach which still allows caching the files, but can force to reload them when needed?

Thanks for any info.

A: 

I've heard talk of using version numbers in the filenames you want you users caching, but I can't speak to how "good" that is compared to other options.

lance
+3  A: 

Append somethign to the URL as parameter, e.g. myresource.css?version=1. The file will be servered correctly, that's a trick to force reloading the cache. You only need to generate the html page dynamically.

ewernli
+1. This is what .Net does when you use embedded web resources.
David
This question seem to cover the subject in more details: http://stackoverflow.com/questions/118884/what-is-an-elegant-way-to-force-browsers-to-reload-cached-css-js-files
ewernli
Hi.Thanks for the link, it seems to give a very through explanation.Also, just to understand your own explanation, is the version parameter will need to be forever kept in the link, and then incremented every time the version upgrades (as in the link that you posted)?Thanks again.
SyBer
Yes, that's the idea.
ewernli
A: 

Options I can think of:

  • Reduce the cache TTL
  • Store the cacheable stuff in a versioned directory tree, e.g.:
    • /app/1.2/css/
    • /app/1.2/js/
Álvaro G. Vicario