Preventing cache on back-button in Safari 5

As of recent safari 5 was released, and it turns out to cause some problems for my website. I have a dynamic website running classic ASP (though that shouldn't matter much) and the site has some creative use of the history stack. For instance, you can be on a page that lists products, then go to details about a product and change the product (admin-view). When you click save on the product the information is sent to the server via AJAX, and a history.back() is issued. This works great in all browsers (including safari <= 4), however, in the newly released safari 5 it stopped working. It seems that when you click back in safari 5 it doesn't actually refresh the page, it only loads it from cache, which means that the changes made in the details view isn't shown. How can I go about to make this work in safari 5 as well? This is the current code I have to turn off caching (included at the top of every 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()

Solution 1:

The empty unload handler will not work anymore. Instead you can check the persisted property of the onpageshow event. It is set to false on initial page load. When page is loaded from bfcache it is set to true.

Kludgish solution is to force a reload when page is loaded from bfcache.

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

If you are using jQuery then do:

$(window).bind("pageshow", function(event) {
    if (event.originalEvent.persisted) {
        window.location.reload() 
    }
});

Solution 2:

After some googeling and digging I've found a solution, though I'm not too happy about it. Setting onunload="" in the body-tag causes Safari to invalidate the page and reload it uppon window.history.back();.

Solution 3:

Here's another way:

    function invalidateBackCache() {
        // necessary for Safari: mobile & desktop
    }

    window.addEventListener("unload", invalidateBackCache, false);

I chose to go this route because adding HTML (onunload="") to the body tag in .Net involved modifying three files in my case. Setting the onunload attribute in jQuery didn't solve it either.

This works for mobile Sarfari (iPad) as well.