Making sure of absolutely no caching

Sometimes, especially ’some’ mobile browsers do not respect the cache-headers you set in html meta tags or as htm headers with php. This is particularly annoiying, when your page or webapp has an error, like a typo or something, that does not get fixed on the client side unless they purge their browser caches manually (and why would they do that?) And in the case of a webapp, they cannot even do that.

So the only secure way is to always load the whole page from another file, adding a changing parameter to the URL so it really is different I have found this working nicely even in webapps installed on the user’s device. They pull the content nicely from a remote fileeverytime they open.

<!DOCTYPE HTML>
<html>
<head>
<script language="Javascript">
     var d = new Date();
     var t = d.valueOf();
     filename ="path_to_html_file?v="+t;
     var request = new XMLHttpRequest();
          request.open("GET", filename, false);
          request.send(null);
          var CODE = request.responseText;
          document.write(CODE);
        document.close();

</script>
</head>
<!-- just in case ;-) -->
<body style="background-color:black;">
</body>
</html>

 

Vastaa