0

I am working on a web application I updated the code In server when coming to the browser it is loading old files only when I try with hard refresh multiple times it is loading new files 

I tried with meta tags

<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />

window.location.reload();

But it is not working.

I am maintaining the version for script files and CSS files. for version management and minification I am using grunt.

For existing users who are already in my application (live users/users who are regular). The script is not updating to check the version how I can update the existing script in the browser

As per my knowledge browser is rendering script from browser cache but I don’t know when it gets the script from the server

The same issue with CSS also.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Sriharsha
  • 11
  • 3
  • Have a look at this answer which details various things you can do https://stackoverflow.com/a/47593331/1663821 but appending a version number to the script is one of the methods. – MikeS Feb 25 '20 at 15:03

1 Answers1

0

You should append a timestamp to css/js files. Like:

<script type="text/javascript" src="/js/1.js?v=1234455"/>

Use this approach:

<script>document.write("<script type='text/javascript' src='//site.com
    /js.js?v=" + Date.now() + "'><\/script>");</script>

This way src will be unique each page load so that new js will be loaded.

mirushaki
  • 897
  • 1
  • 10
  • 13