I've created a simple HTML, SASS, JS website and each time im uploading new files, to actually see the changes appear on the website I need to clear my browsing data.
is there anyway to address it via vanilla js headers, or a button on the website to clear cache?
CodePudding user response:
You can create a button that deletes the cache for that page like this :
<button>Clear cache </button>
let btn = document.querySelector("button");
btn.addEventListener("click",()=>{
window.location.reload(true);
window.location.reload(); // few browsers don't require for a parameter to be passed
})
To know more about window.location.reload(true)
CodePudding user response:
There isn't a way to programmatically empty browsers cache
You can only set some meta tags to ask the browser to load the page without using cache
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
These are some links I recommend you to checkout to learn more about it :