【问题标题】:fallback cache manifest does'nt work后备缓存清单不起作用
【发布时间】:2012-10-11 22:33:19
【问题描述】:

我找不到像我这样的另一个问题,所以这里是:

我有这个缓存清单文件:

CACHE MANIFEST

CACHE: 
./index.html
./offlinetest.js
./offline.html
./cache.manifest
./cache.manifest.php
./online.html

# Hash: 800d285afdd44dae60eb95bf479a94bf

NETWORK:
./index.html
./online.html

FALLBACK:
./index.html ./offline.html
./online.html ./offline.html

当我关闭 wifi 开关并尝试访问 online.html 时,会提供此文件而不是 offline.html!为什么?我正在使用铬。

另一个问题是 Firefox,当我尝试这个时,我有:0 items in offline cache

有人可以解释一下吗,我在搜索的所有地方都没有看到类似的问题

【问题讨论】:

  • 您可以查看浏览器正在缓存哪些文件。只需更改哈希即可。完成后,您应该在 Chrome 中加载新站点并查看控制台中缓存了哪些文件。
  • hash 是用 md5_file() php 函数自动生成的,所以如果文件改变了,hash 也会改变。这不是问题,问题是为什么我下线时永远无法到达offline.html。
  • 根据规范,您的服务器还应发送带有日期的过期标头,以便缓存文件,如果我理解正确,您是否在您的网络服务器中进行了配置?
  • 是的,我在 apache2.conf 中配置了一些东西,但没有为 text.html 类型配置:ExpiresActive on ExpiresByType text/css A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType text/javascript A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/png A2592000 ExpiresByType image/gif A2592000 ExpiresByType text/js A2592000
  • 尝试添加 text/htmlapplication/xhtml+xml 以及

标签: html caching manifest offline fallback


【解决方案1】:

./online.htmlCACHE: 部分下。删除它,您的 Web 应用程序应该会检索到 offline.html。断开连接时获得 online.html 的原因是因为您正在缓存它。

【讨论】:

    【解决方案2】:

    我自己也在为此苦苦挣扎,解决方案:

    1. 您必须先清除缓存
    2. 重新加载您的页面
    3. 再次重新加载(听起来很愚蠢,我知道),然后将使用文件中的新版本,并且 再次缓存。

    然后保持这个语法:

    FALLBACK:
    //static.html will be served if main.py is inaccessible
    /main.py /static.html
    //offline.jpg will be served in place of all images in images/large/
    images/large/ images/offline.jpg
    // offline.html will be served in place of all other .html files
    *.html /offline.html
    

    一些可以帮助你的更多信息:

    回退: 如果资源不可访问,则指定后备页面的可选部分。第一个 URI 是资源,第二个是回退。 两个 URI 必须是相对的,并且与清单文件来自同一来源。可以使用通配符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 2016-07-24
      • 1970-01-01
      • 2011-11-30
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多