Back cache caching in Safari 5

As of recent safari 5 has been released, and this, as it turned out, causes some problems for my site. I have a dynamic website with classic ASP (although that doesn't really matter), and the site has creative use of the history stack. For example, you can be on the page where the products are listed, and then go to the product details and change the product (admin-view). When you click "Save" on the product, information is sent to the server through AJAX, and history.back() is issued. This works fine in all browsers (including safari <= 4), however in the recently released safari 5 it stops working. It seems that when you click on safari 5 it doesn’t actually refresh the page, it only loads it from the cache, which means that the changes made to the details view are not displayed. How can I continue this work in safari 5? This is the current code that I have to disable caching (included at the top of each page):

 Dim pStr pStr = "private, no-cache, no-store, must-revalidate" Response.AddHeader "pragma","no-cache" '? Response.AddHeader "cache-control", pStr '? Er ikke sikker på om disse 3 siste er nødvendige. Response.AddHeader "cache-control", "post-check=0, pre-check=0" '? Er ikke sikker på om disse 3 siste er nødvendige. Response.AddHeader "Expires", "Mon, 26 Jul 1997 05:00:00 GMT" '? Response.AddHeader "Last-Modified", Now() 
+23
safari cache-control
Mar 14 2018-11-11T00:
source share
3 answers

An empty unload handler will no longer work. Instead, you can check the persisted property of the onpageshow events. It is set to false on initial page load. When a page is loaded from bfcache, it is true.

Kludgish's solution is to force a reload when loading a page from bfcache.

 window.onpageshow = function(event) { if (event.persisted) { window.location.reload() } }; 

If you are using jQuery, follow these steps:

 $(window).bind("pageshow", function(event) { if (event.originalEvent.persisted) { window.location.reload() } }); 
+45
Mar 19 '13 at 10:52
source share

After some googeling and digging, I found a solution, although I'm not too happy with it. Setting onunload="" in the body tag calls Safari to cancel the page and reload up window.history.back(); .

+7
Mar 14 '11 at 23:37
source share

Here's another way:

  function invalidateBackCache() { // necessary for Safari: mobile & desktop } window.addEventListener("unload", invalidateBackCache, false); 

I chose this route because adding HTML (onunload = "") to the body tag in .Net involved changing three files in my case. Setting the onunload attribute in jQuery also did not solve it.

This works for mobile Sarfari (iPad).

+3
Sep 22 '11 at 16:33
source share



All Articles