How to tell Chrome to clear cache and cookies from a website?

16,905

Solution 1

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).

Solution 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>`
Share:
16,905
Delonous
Author by

Delonous

Updated on June 05, 2022

Comments

  • Delonous
    Delonous almost 2 years

    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!