0

Possible Duplicate:
Force refresh of cached data

Whats the best practice for updating the css style sheet after a website goes through visual changes?

I recently updated my webpage with new images and updated the css. When my friend viewed the site his browser had the previous css rending with new images for some reason. He has visited the site before. From my understanding the style sheet was not refreshed but they images changed on his first launch of the site causing it to appear incorrectly. After he refreshed the page it updated the css and looked alright though.

Do I need to change the name of the css after major changes to force the new style sheet to be downloaded? Or is there a way to cause the browser to perform a mandatory reload of the style sheet?

Community
  • 1
  • 1

3 Answers3

3

He has the previous version because it is cached. On his end, he can "force" a fresh CSS file by using cntrl + f5 (on chrome) or his browsers equivalent. Or merely empty his cache.

For you, what you can do is change the name of the stylesheet. You could do this by adding a ?=x to the stylesheet href. It makes the browser think it is a new version, but is infact just the old version.

If you never want the file to be cached again (which I don't recommend) you could add a timestamp to the ?=, but again, I don't recommend that

Andy
  • 14,427
  • 3
  • 52
  • 76
1

The browser is caching the CSS file. If this is a problem during development you can use a trick like timestamping your script link: described here

In production this is not generally a problem and can be solved by the user clearing his cache. Generally browsers will pick up the changes on refreshing.

Ben McCormick
  • 25,260
  • 12
  • 52
  • 71
0

A common solution is like this: <link href="css/style.css?<?php echo time();?>" which will force the browser to re-download the css file. The browser will think that this is a new file.

tibkov
  • 21
  • 3