HOw do I get browser to get my latest version of a page
I have applications that run within the browser. When I make changes to pages and javascript I start getting calls from users who get weird results. I tell them to clear their cache and all is well.
Is there a way that I c开发者_开发百科an force, or suggest to, the browser to get a new version of the page?
thanks
You can set a Cache-Control: no-cache
header on the server-side to prevent the browser from caching your files.
Edit:
See this page for info on stopping caching of pages:
http://www.webmasterworld.com/forum21/10628.htm
See suggestions for .js/.css on this answer:
How to force browser to reload cached CSS/JS files?
The idea is to timestamp filenames when they change, so the filename changes and the browser is forced to load a new copy.
So I think I found the perfect solution. I discovered that if you put a ? and some unique character after the file name, it forces the browser to get a new version when that version changes.
So instead of:
<link href="css/mycss.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/ngen.js"></script>
code:
<link href="css/mycss.css?1.0.28" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/ngen.js?1.0.28"></script>
and since I use php, I create a global with the release in my main config.php and tack that on to the file reference.
$GLOBALS['V_UNIQUE'] = "?1.0.28" // my current release number
<link href="css/mycss.css?1.0.28<?php echo $GLOBALS['V_UNIQUE']?>" rel="stylesheet" type="text/css" />
精彩评论