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

不羁岁月 提交于 2019-12-02 17:59:46
christophe

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.

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.

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.

For our iOS webclip apps we are using the following. So far no cache problems:

1- We have one cache manifest file called 'manifest.appcache.php'

<?php
    header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
    header("Pragma: no-cache");
    header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
    header('Content-type: text/cache-manifest'); 
?>

CACHE MANIFEST

CACHE:
# Don't cache anything
FALLBACK:
# Nothing
NETWORK:
# Request everything from server
*

2 - In the HTML file we have:

<!DOCTYPE html>
<html lang="en" manifest="manifest.appcache.php">
    <head>
...

I have an angular app I'm developing and ran into this issue when trying to test it on an iPad. By adding a meaningless query to the end of the url I was able to get a current version of all the assets.

www.somesite.com?meaninglessquery

You can force the open web app to reload without using the cache if you have the Safari Web Inspector open and pointing at your open web app. With the Web Inspector active, press SHIFT + COMMAND + R (on a Mac). You may need to refresh one more time to trigger the updated assets.

I've had luck with powering off the device. I had changed the app manifest; but presumably, you need a refresh or something to get the browser to look for it. Since I removed the browser chrome, there's no reset button. We tried "closing" the app (haha) and swiping the app away; but I presume iOS tends to keep things running anyway. Shutting down did the trick to get it to refresh.

Maybe there's some gesture for refresh I don't know. Perhaps one should tuck a little "check for updates" refresh button into cached web apps.

Chen Lim

The latest Safari (v12.0.1) developer tools has a "Ignore resource cache" button at the top right of the Network tab. Check that, then reload.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!