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 th开发者_JAVA技巧e 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.
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.
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.
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/
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%>" />
精彩评论