2

So I just recently updated a website through FileManager (Network Solutions). And I'm having an issue where Chrome is basically saving the previous files so the site would load faster. Problem is, the new site doesn't work to well with the old files. I therefore have to go into Privacy and clear my data for the website to refresh correctly to show my updated website.

Is there anyway to solve this issue with the code on the front end? Because for people who don't clear their browsing history often, the website will look broken to them. Thanks for the help!

Delonous
  • 201
  • 2
  • 5
  • 11

3 Answers3

5

As Raccoon suggests, using headers to tell the browser to not cache might solve some of this.

A hack would to set a timestamp as a query parameter on the updated (or all) scripts you're using <script src="js/myfile.js?updated=1492974572411"></script>. This works for css files as well.

A cleaner and more manageable solution is to let the browser do it's thing, and instead change the names of the files you've updated. I suggest using generating a random hash. Using the same example as above, it would mean using something like the following: <script src="js/f8dc525b.myfile.js"></script>

Webpack for instance can generate this hash for you, but you can easily generate this value yourself either by using a library, or by doing something like Math.random().toString(16).slice(2).

Community
  • 1
  • 1
2

you can try using JavaScript window.location.replace() function:

<meta http-equiv="refresh" content="0; http://www.redirecturl.com/" />
<meta http-equiv="pragma" content="no-cache">
<script type="text/javascript">
window.location.replace('URL');
</script>`
Martins
  • 508
  • 4
  • 12
0

For cache if your server has php use

<?php
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
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");
?>

Or if you want to use js to clear it use window.location.reload(true)

Raccoon
  • 34
  • 9