如何强制刷新已添加书签的 iPad 主屏幕 Web 应用程序?
我遇到了一个问题,我将一个网络应用程序添加到我的 iPad 主屏幕 (iOS 5.0.1 iPad 2),当我打开它时,它似乎在幕后缓存某些内容,独立于 Safari。
我已经清除了 Safari 中“设置”中可用的所有内容(清除历史记录和清除 Cookie 和数据),当我使用 Safari 导航到 Web 应用程序时,我看到该应用程序处于当前状态。但是,如果我打开主屏幕书签,我会得到应用程序处于预更改状态。
我已经看到很多有关使用 cache.manifest 缓存资源以供离线使用的信息,但我不确定这是否与此相关,因为我想要完全相反的内容:不缓存任何内容。
我已经达到了甚至不测试外部资源的程度;如果我更改 index.html 的 body 元素中的某些任意测试字符串,主屏幕书签不会显示更新的文本。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
另一种解决方法是将 ?v=1 添加到 Javascript 和 CSS 链接中。例如:
据我所知,当您的文件发生更改时,似乎不必更新号码。显然,在安装了最新软件更新的 iPad 2 上,仅仅暗示一些动态就足够了。
Another workaround is to add ?v=1 to your Javascript and CSS links. For example:
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.
创建一个
cache.manifest
指示它永远不要缓存主 html 页面引用的资源:在您的
index.html
中使用它:现在,每当您更改该清单文件时 --例如,通过增加该评论中的版本号,浏览器也会重新下载
index.html
。确保缓存更新时重新加载页面:
Safari 开发者库有很好的文档。
Create a
cache.manifest
that instructs it never to cache resources referenced by the main html page:Use it in your
index.html
: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:
The Safari Developer Library has good documentation.
我想我找到了一个解决方法:
该网站的新版本仅在 index.html 文件更改时出现。
(要加载的第一个文件)
如果您保留index.html并且仅更改其他文件中的一些js,则站点不会加载新版本。
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.
对于我们的 iOS webclip 应用程序,我们使用以下内容。到目前为止,没有缓存问题:
1- 我们有一个名为“manifest.appcache.php”的缓存清单文件
2- 在 HTML 文件中,我们有:
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'
2 - In the HTML file we have:
我正在开发一个 Angular 应用程序,并在尝试在 iPad 上测试它时遇到了这个问题。通过在 url 末尾添加无意义的查询,我能够获取所有资产的当前版本。
www.somesite.com?meaninglessquery
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
如果您打开了 Safari Web Inspector 并指向打开的 Web 应用程序,则可以强制重新加载打开的 Web 应用程序,而不使用缓存。在 Web Inspector 处于活动状态时,按
SHIFT + COMMAND + R
(在 Mac 上)。您可能需要再刷新一次才能触发更新的资源。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.我很幸运地关闭了设备。
我更改了应用程序清单;但想必您需要刷新或进行其他操作才能让浏览器查找它。
由于我删除了浏览器镶边,因此没有重置按钮。我们尝试“关闭”应用程序(哈哈)并将应用程序刷走;但我认为 iOS 无论如何都会让事情保持运行。
关机可以让它刷新。
也许有一些我不知道的刷新手势。也许应该在缓存的网络应用程序中添加一个“检查更新”刷新按钮。
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.
将 ?v=1.1 添加到 index.html 文件并根据需要更新版本,它将完成这项工作。我将它用于 Flutter web 和其他
!DOCTYPE html> <头>您的应用标题 <正文> <脚本 src="app.js?v=1.1">
?v=1.1" 将其添加到样式表和 js 文件中Add the ?v=1.1 to the index.html file and update the version as needed and it will do the job. I used it for Flutter web and for others
!DOCTYPE html> <html> <head> <title>Your App Title</title> <link rel="stylesheet" href="styles.css?v=1.1"> </head> <body> <script src="app.js?v=1.1"></script> </body> </html>
?v=1.1" add this to stylesheet and js file最新的 Safari (v12.0.1) 开发者工具的“网络”选项卡右上角有一个“忽略资源缓存”按钮。检查一下,然后重新加载。
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.