Avoiding caching in the browser when replacing page content with document.write ()

I'm struggling a bit with browser caching.

I have a static HTML page (let's call it index.html), which includes javascripts that do the magic (embedding an interactive service). These scripts have an AJAX response error handler that looks like this:

function(response){ // response is prototype.js AJAX response document.open("text/html"); document.write(response.responseText); document.close(); } 

When this is called and the contents of the document are replaced, the browser caches (I do not want it to be able to be transferred), and pressing F5 does nothing. Ofc. CTRL + F5 is working fine, but I cannot assume that the user will do this.

This function is the AJAX error handler that I receive. It is used to replace the contents of the page on the user error page to which the front-end Apache HTTP server responds, which has a reverse proxy server to another Apache HTTP server, which again has a reverse proxy server for Tomcat, which serves scripts and processes requests from them.

The Front Apache HTTP server has its own command to override the configuration page and cache control headers for index.html:

 ProxyErrorOverride On <Files index.html> Header set Cache-control "no-cache, no-store, max-age=0, must-revalidate" Header set Pragma "no-cache" ExpiresByType text/html "access plus 1 second" </Files> 

So caching index.html seems to be off for me. I assume that you see that I am using mod_proxy, mod_headers, mod_expires.

The error page is equipped with meta tags for managing the cache (I know, I know that they cannot be taken into account;) and allows us to say that the header looks like this:

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate, max-age=0" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Thu, 01 Jan 1970 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /> 

So at the end, my script looks something like this:

  • page is loading
  • javascripts are loaded and called, magic begins (the service is embedded in the designated div and starts talking to the server using AJAX).
  • Tomcat / Inner HTTP server is down (I don't know how to maintain / update software)
  • scripts receive AJAX error responses (which responseText is a user error page overridden by the front Apache HTTP server with its error page).
  • page content is replaced by user error page
  • server with 4. gets up (or even not, then it will be processed from different levels)
  • user hit the F5 page reloaded (but it is not)

I can be chaotic here, so if something is unclear or I need to give more detailed information, ask, I will try to provide additional information as soon as possible.

PS: I believe that I could be fundamentally mistaken in my approach or do something stupid. If so, let me know.

EDIT:

This actually happens on ff (16.0.2, 17.0) and IE9. Chrome, Opera, and Safari simply reload the page without caching. Oh, this is even worse than ff and does not update to ctrl + f5 only when you press enter in the address bar: P

In ff, I get wycywig: /// in the documentURI property

+4
source share
1 answer

Do you use IE? IE loves to cache AJAX requests, regardless of the response to the cache header. You tried adding the cache delete request line to the request URL like this:

 var cacheBuster = '?buster=' + (new Date()).getTime(), //add a timestamp url = '/my/url' + cacheBuster; new Ajax.Request(url, { //... your ajax request }); 
0
source

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


All Articles