5

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.

SyBer
  • 5,407
  • 13
  • 55
  • 64

4 Answers4

7

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
  • 38,045
  • 5
  • 92
  • 123
  • +1. This is what .Net does when you use embedded web resources. – David Jan 12 '10 at 17:07
  • 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 Jan 12 '10 at 17:10
  • 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 Jan 12 '10 at 17:39
0

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
  • 16,092
  • 19
  • 77
  • 136
0

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 González
  • 142,137
  • 41
  • 261
  • 360
-1

You can use below format for auto random versioning

for js file:

<script type="text/javascript" src="js/app.js?seq=<%=DateTime.Now.Ticks%>"></script>

and for css file:

<link rel="stylesheet" type="text/css" href="Styles/styles.css?seq=<%=DateTime.Now.Ticks%>" />

Pritam Jyoti Ray
  • 320
  • 1
  • 8
  • 12