2

I constantly find that when I update a website, I am having to tell the other people in the office to Shift+F5, as the browser doesnt immediately recognise that the website has changes and loads either the old HTML with the new CSS or vice versa.

How can I force the browser to load a new version of the site once I've made an update? Or is it just people who are on the same network as me encounter these things? I have tried putting a random number at the end of my style.css includes, such as:

<link rel="stylesheet" media="screen" href="/inc/style.css?rnd=493481" />

However that doesn't seem to make any difference whatsoever. I don't need it to reload HTML and CSS everytime the page loads, just when I make major updates.

Any advice?

Chud37
  • 4,907
  • 13
  • 64
  • 116
  • 1
    possible duplicate of [Force browser to clear cache](http://stackoverflow.com/questions/1922910/force-browser-to-clear-cache) – Naeem Shaikh Feb 11 '15 at 12:01
  • Probably the headers of the site telling the browser to cache everything. – Pinoniq Feb 11 '15 at 12:01
  • did you try ``? – rasso Feb 11 '15 at 12:02
  • regarding css ref, having the page generate a random number and put it at the end as qs param is not a good idea. it is possible to regenerate the same number and call a cached version of the css file. i generally use`v=1` the first time i update the page. and after the second update i simply increase the param value of `v` like `v=2` manually. – rasso Feb 11 '15 at 12:07
  • @OzgurBar But as I said, the random number didn't work at all. Is there some special param in `?v=`, as I was calling it some random string name? – Chud37 Feb 11 '15 at 12:08
  • @Chud37 I think that would be possible only if the browser is not parsing the most recent markup of the page. if it did, it would reload the css since the value of `href` attribute looks completely different. Is the page in an iframe or something? – rasso Feb 11 '15 at 12:13
  • @OzgurBar No, its not. And I just a second a go tried it, and the page loaded weirdly: `` Loaded the old version :( – Chud37 Feb 11 '15 at 12:14
  • @Chud37 that is weird. I'd say "maybe that's because you've already used `v=1` in the past while generating randoms" but you used `rnd=`, not `v=`. which browser are you on? – rasso Feb 11 '15 at 12:21
  • @Chud37 don't know if you have an application delivery controller, but I remembering having a problem similar to this with `netscaler` due to caching. – rasso Feb 11 '15 at 13:17

2 Answers2

1

Modern browsers ask the server when the (css) file changed last time and check if their cached versions last change time matches. If it didn't match the browser knows that the servers version changed and use that version instead of the chached one.

But your server has to support the last-changing-time check. May your server don't or it's disabled?

I don't recomment to disable caching generally - it 'll give your server unnecessary traffic. Best solution in that case would be (as already said by user2440252) is to use version specific names.

Verim
  • 1,065
  • 9
  • 17
0

The browser cashes the css and js files client side. the most effective way is to make your css and js files specific to that version. FE

Website version 1.2 links to main-1.2.cc etc

this way the browser sees its another file and updates automaticly

Ivan Sander de Jong
  • 835
  • 1
  • 11
  • 28