html - 为什么我的缓存 webapp 没有在第一次尝试时刷新更改?

标签 html ios firefox caching web

我正在关注 this tutorial并在我的 iPad 上试用。教程说:

You can wait for the application cache to update automatically or trigger an update using JavaScript. The application cache automatically updates only if the manifest file changes. It does not automatically update if resources listed in the manifest file change. The manifest file is considered unchanged if it is byte-for-byte the same; therefore, changing the modification date of a manifest file also does not trigger an update. If this is not sufficient for your application, you can update the application cache explicitly using JavaScript.

所以我一直在做的尝试强制更新是更改 list 文件中的注释,其中有一个版本号。 EG,我改变这一行:

# Cache Manifest Version: 1.6

我的 html 标题如下所示:

<!DOCTYPE html>
<html lang="en" manifest="cache.manifest">
<head>
    <meta charset="UTF-8"/>
    <title>Canvas tutorial</title>

    <link rel="stylesheet" type="text/css" href="app.css">
    <meta name="viewport" content="width=640; user-scalable=no;"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>

我有一个在 iPad Safari 中呈现的网站版本,我已将其添加到我的主页。如果我进行更改,例如向我的应用程序的 html 添加一些文本,则:

  1. 我必须在 Safari 中刷新两次才能看到变化。
  2. 我必须在“添加到主页版本”中刷新两次才能看到更改。
  3. 即使我在桌面上尝试使用 firefox,也需要刷新两次才能看到我的更改。

为什么会这样?为什么它在第一次刷新时不起作用?

iOS 7“添加到主页”更新

我发现此文档不适用于 iOS 7 中的“添加到主页应用程序”。缓存决定定期刷新,据我所知,您无法控制它(也许您使用 javascript ,但我还没有尝试过)。

幸运的是,我找到了解决方法。看这里:https://stackoverflow.com/a/19674061/61624

最佳答案

通过观察痕迹(在 Chrome 上) 我看到浏览器不等待应用程序缓存刷新结束以显示来自现有应用程序缓存的请求页面

然后浏览器显示之前的版本。

我想一个解决方案是:检测页面中的应用程序缓存刷新完成事件,然后以编程方式重新加载(HTML5 功能)。

我发现 http://www.html5rocks.com/en/tutorials/appcache/beginner/

以下代码可能对您有所帮助。 (代码请求刷新权限,但在您的用例中,代码可能会更新以立即重新加载。)

// Check if a new cache is available on page load.
window.addEventListener('load', function(e) {

  window.applicationCache.addEventListener('updateready', function(e) {
    if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
      // Browser downloaded a new app cache.
      if (confirm('A new version of this site is available. Load it?')) {
        window.location.reload();
      }
    } else {
      // Manifest didn't changed. Nothing new to server.
    }
  }, false);

}, false);

希望对你有帮助

关于html - 为什么我的缓存 webapp 没有在第一次尝试时刷新更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19193457/

相关文章:

ios - AppStore 应用内区域价格是如何计算的?

javascript - 单击缺货变体时,产品 URL 不会更改 - Shopify

javascript - 如何根据点击的链接更改点击事件的结果

ios - 我无法弄清楚这种崩溃:[__NSArrayM insertObject:atIndex:]:对象不能为nil

ios - 如何与其父 SKShapeNode 一起旋转 SKLabelNode?

javascript - 错误 : No window matching {"matchesHost":[]} for tabs. insertCSS()

javascript - 在 Firefox Addon SDK 中存储/访问简单变量

javascript - XPCOM stub 文件

javascript - CSS 在不使用 flexbox 的情况下在固定宽度元素旁边使输入宽度响应

html - Bootstrap 3 : Missing gutters