Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Last active February 24, 2021 09:55
Show Gist options
  • Save DavidWells/590e2ae44894de612446 to your computer and use it in GitHub Desktop.
Save DavidWells/590e2ae44894de612446 to your computer and use it in GitHub Desktop.
Clear Browser cache. Run in your browsers javascript console
//Cache Buster
(function (){
  var rep = /.*\?.*/,
      links = document.getElementsByTagName('link'),
      scripts = document.getElementsByTagName('script'),
      process_scripts = false;
  for (var i=0;i<links.length;i++){
    var link = links[i],
        href = link.href;
    if(rep.test(href)){
      link.href = href+'&'+Date.now();
    }
    else{
      link.href = href+'?'+Date.now();
    }
  }
  if(process_scripts){
    for (var i=0;i<scripts.length;i++){
      var script = scripts[i],
          src = script.src;
      if(rep.test(src)){
        script.src = src+'&'+Date.now();
      }
      else{
        script.src = src+'?'+Date.now();
      }
    }
  }
})();
@bhavanimandapati
Copy link

But in react js this technique is not working. updated changes are not reflecting without refresh the browser. can you suggest me any other solution. Thanks in Advance.

@AgostinoA
Copy link

Hi, What is other solutions ? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment