How to clear cache from html page?

I am trying to clear the browser cache on page load and / or prevent page caching. Here's what's inside my head and it doesn't work:

<meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="-1" /> 
+4
source share
2 answers

Your meta code should work with most browsers for web content. However, for resource files (javascript, images, css) your mileage may vary. Most cache brute force strategies include changing the name of your resource files (possibly dynamically) or using Apache rewrite rules to pretend that the names are changed. This Google search should put you on the right track.

 cache busting strategy for js 

Good luck.

+3
source

For this, meta tags are enough for you. However, for resources, it can change. Just attach the variable to the file name, for example:

 var img = new Image(); img.src = 'image.jpg?'+ Math.random() 

or

 img.src = 'image.jpg?'+ new Date().getTime() 

if you use javascript to load resources. Or you can write a rule for the Apache mod_rewrite engine to automatically write a random hash.

However, I believe that there should be a more elegant solution

+1
source

Source: https://habr.com/ru/post/1400861/


All Articles