Snackmoore
Snackmoore

Reputation: 935

How to STOP iOS Safari web page from loading cached pages after adding to home screen?

I have added a website to the iOS home screen. If a load open the website from the iOS home screen, it seem to be always loading a cached page. Even if I updated the page or delete the page entirely, it still load the original version.

It will load the updated page if I open the site directly from iOS Safari instead of clicking the icon on the home screen.

The site is hosted on Apache running Ubuntu 11.10.

I have added following inside

and added

in attempt to force it to load the updated page.

I have also tried clear the cache and cookie and history from iOS Safari setting and also rebooted the ipad and nothing seem to work.

Please help~!

Upvotes: 4

Views: 8693

Answers (1)

aroth
aroth

Reputation: 54806

This should do it, though it will result in double-loading of your page in instances where it is not initially loaded from a cached copy.

<script>
    var url = window.location.href;
    if (url.indexOf('rnd=') == -1) {
        url = (url.indexOf("?") == -1 ? url + "?rnd=" : url + "&rnd=") + Math.random();
        window.location.href = url;
    }
</script>

So basically you would add http://mysite.com/myCoolPage.html to the iOS home screen, and then whenever the page is loaded in the browser it will redirect to http://mysite.com/myCoolPage.html?rnd=xxxxxxx, effectively preventing it from being cached.

Upvotes: 1

Related Questions