14

Like the title says, Google Chrome refuses to load newer versions of a Javascript file.

I've tried:

  • Ctrl + F5
  • Dev Console > Network Tab > Disable Cache
  • Disable Cache, Then With Dev Console Still Open Right Click Refresh > Empty Cache and Hard Reload
  • Disable Cache, Then With Dev Console Still Open Ctrl + F5
  • Chrome Settings > Manually Delete All Cache From Beginning Of Time, Then Ctrl + F5

Basically everything listed here: Chrome WON'T clear cache... ctrl + F5 doesn't seem to work either

None of this worked. The sources panel still shows that the old Javascript file was being loaded. The absolutely mind-boggling thing is that when I right click the file in the sources panel and then select open in new tab, the updated file opens in a new tab, but then refreshing the page still brings up the old file in the sources panel of dev console.

The only thing that has gotten Chrome to work for me is to manually append ? and a random number at the end of the file name. That seems to force Chrome to actually load the new file. As of now, I've been using PHP to add a

<script type="text/javascript" src="file.js<?php echo '?' . rand(); ?>"></script>

in order to get anything to load correctly in Chrome, but this seems like a terrible solution.

My question is, How do I get Chrome to actually reload Javascript files from the server instead of the cache?

mt_xing
  • 631
  • 7
  • 22
  • Can you show us actual file HTTP requests? You can use Chrome DevTools [Copy All as HAR](https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#copy) feature, [Fiddler](http://www.telerik.com/fiddler) or any other web development tool. – Leonid Vasilev Jan 18 '18 at 11:02
  • I am seeing the same thing, even clearing from the application tab, there is not Cache API from a service worker or any other cache besides standard browser cache. It does show as updated in a private window and eventually after 30 minutes or so clears on it's own. – Alex Borsody May 11 '20 at 23:03
  • If I view the file directly it does not show as updated, I need to append a cache buster parameter like ?sdfsdf, then I see the updated file. – Alex Borsody May 11 '20 at 23:10
  • can you try this echo ""; on the top of file; – Muhammad Numan May 18 '20 at 21:27

3 Answers3

2

Have you tried completely wiping your cache ?

C:\Users\yourusername\AppData\Local\Google\Chrome\User Data\Default\Cache

1

You can fix the problem at server end by adding to the response header:

Cache-Control: must-revalidate

Also if you want to use Ctrl+F5, do this after opening the developer console - it should work. Make sure to check 'disable cache' in network tab in the developer console.

Ishita Singh
  • 297
  • 1
  • 6
-2

It is incredibly annoying. You can force a reload by opening the inspect window in Chrome and selecting Network and Disable cache.

Other than that Ctrl+F5 doesn't work.

Karlth
  • 3,267
  • 2
  • 27
  • 28