1

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 can force, or suggest to, the browser to get a new version of the page?

thanks

sdfor
  • 6,324
  • 13
  • 51
  • 61

3 Answers3

3

You can set a Cache-Control: no-cache header on the server-side to prevent the browser from caching your files.

casablanca
  • 69,683
  • 7
  • 133
  • 150
  • As long as the browser honors it. Which is why it is suggested to use multiple no-cache methods, as in my first link. – mellamokb Feb 21 '11 at 17:31
1

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.

Community
  • 1
  • 1
mellamokb
  • 56,094
  • 12
  • 110
  • 136
  • What about cached HTML? Yesterday I changed the HTML of a dialog and a few people get a blank dialog, while most work? – sdfor Feb 21 '11 at 17:25
1

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" />
sdfor
  • 6,324
  • 13
  • 51
  • 61