1

I updated the images and stylesheets on my website, but I am getting phone calls from clients saying my layout looks weird. When they refresh the page, it looks normal.

How do I stop their browsers from loading my website from cache?

ace
  • 7,293
  • 3
  • 23
  • 28
steeped
  • 2,613
  • 5
  • 27
  • 43
  • 1
    Are there any caching mechanism used directly by your site? I'm thinking of CMS caching, in particular. – Seth Battin Oct 26 '12 at 02:53
  • 1
    This [SO question](http://stackoverflow.com/questions/118884/what-is-an-elegant-way-to-force-browsers-to-reload-cached-css-js-files) is a good read. – ace Oct 26 '12 at 02:54
  • In addition to Mohamed's answer, you can also put this html in the head section: `` – paddotk Feb 12 '13 at 14:19

2 Answers2

1

use one of the static file versioning techniques

such as adding a querystring to the static file /img/image1.jpg?v=1.0 or rename the file /img/image1_1.0.jpg

this applies to any image, JavaScript, or CSS files

MikeM
  • 27,227
  • 4
  • 64
  • 80
1

You can use meta tags to tell the browser not to cache the page:

You can also generate raw headers. Please read HTTP specifications

<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>