Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you force an iPad home screen bookmarked web app to refresh?

I've run into a problem where I add a web app to my iPad home screen (iOS 5.0.1 iPad 2), and when I open it it appears to be caching something behind the scenes, independent of Safari.

I've cleared out everything from Safari that's available in Settings (Clear History and Clear Cookies & Data), and when I navigate to the web app with Safari I see the app in its current state. However if I open the home screen bookmark I get the app in a pre-changed state.

I've seen a lot of information about using a cache.manifest to cache resources for offline use, but I'm not sure if that's relevant to this since I would like the exact opposite: cache nothing.

I've gone to the level of not even testing external resources; if I change some arbitrary test string in the body element of my index.html, the home screen bookmark does not show the updated text.

like image 260
M Marsh Avatar asked Jan 09 '12 17:01

M Marsh


3 Answers

Another workaround is to add ?v=1 to your Javascript and CSS links. For example:

<link rel="stylesheet" type="text/css" media="all" href="./css/ipad.css?v=1">    
<script src="./js/ipad.js?v=1"></script>

It seems one doesn't have to update the number when your file has changed, as far as I can tell. Apparently, on an iPad 2 with the latest software update installed, it is enough to just hint at something dynamic.

like image 135
Hendrik Avatar answered Nov 05 '22 13:11

Hendrik


Create a cache.manifest that instructs it never to cache resources referenced by the main html page:

CACHE MANIFEST

# Version 1.0000

NETWORK:
*

Use it in your index.html:

<!DOCTYPE html>
<html manifest="cache.manifest">

Now whenever you change that manifest file -- for example, by increasing the version number in that comment -- the browser will redownload index.html also.

Ensure your page gets reloaded when the cache is updated:

<script>
function updateSite(event) {
    window.location.reload();
}
window.applicationCache.addEventListener('updateready', updateSite, false);
</script>

The Safari Developer Library has good documentation.

like image 14
Tom K Avatar answered Nov 05 '22 13:11

Tom K


I think I found a workaround:

The new version of the site only appears when the index.html file changes.
(the first file to be loaded)

If you leave the index.html and only change some js in other files then the site doesn't load the new version.

like image 8
christophe Avatar answered Nov 05 '22 12:11

christophe