0

I have a PHP website with lot of JS and CSS files included with the tag. The problem is whenever I update any JS or CSS and then open my website, chrome is still loading old versions of the JS,CSS . I know client side we can force refresh by Ctrl+Shift+R , but it's too tough to instruct my website users to do this every single time.

I have tried these but still no luck. So please suggest a way to force the browser to reload JS from my server every time instead of cache.

<meta http-equiv="cache-control" content="no-cache"> <!-- tells browser not to cache -->
<meta http-equiv="expires" content="0"> <!-- says that the cache expires 'now' -->
<meta http-equiv="pragma" content="no-cache"> <!-- says not to use cached stuff, if there is any -->
Rangarajan K
  • 43
  • 1
  • 12

2 Answers2

0

try this

<?php

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
needitohelp
  • 93
  • 1
  • 7
0

add a version id like this, example.com/js/example.js?$versionid,if you do this for debug,you can disable chrome cache in developer tools

  • can you explain a bit more ? my JS file don't have any versions. so what version id should I give – Rangarajan K Jul 18 '17 at 03:22
  • I know this is an old answer, but I'll elaborate for anyone reading. By putting a query string with any random value (not necessarily a version number), the browser will treat the file you're loading like it's a new file. That's why this works. – Nicholas R. Grant Sep 20 '18 at 19:09