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()
If you haven't already enable the Develop menu on Safari, with Safari open use the menu to go to Safari > Preferences…. One the preferences window select the Advanced tab. At the bottom there is a checkbox to enable the Develop menu. To disable caching in Safari toggle the menu item under Develop > Disable Caches.
Where to find the Cache files of Safari, Firefox and other Applications? The location of cache files is in your ~/Library/Containers/com. apple. Safari/Data/Library/Caches (earlier versions of macOS: ~/Library/Caches/ ) folder.
November 9, 2022 · 4 min read. Loading a new web page takes time, but about 20% of mobile navigations are actually initiated by the browser Back and Forward buttons. The back/forward cache speeds up these navigation by restoring previously loaded page content.
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()
}
});
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();
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With