gpt4 book ai didi

html - 无法让 HTML5 AppCache 正常工作

转载 作者:行者123 更新时间:2023-11-28 00:15:21 32 4
gpt4 key购买 nike

我正在尝试向我维护的应用程序添加一些离线缓存。这是我第一次不得不使用 AppCache,所以我决定先用一个小的演示站点来测试它。到目前为止,我还无法使它的离线部分正常工作。 Chrome 似乎正在缓存 index.php,因为打印出的日期/时间在页面上永远不会改变,即使我在脚本中发送所有那些无缓存 header ,尽管在 Firefox 中日期更新正确。当我离线时(通过禁用我的网络适配器)Chrome 继续显示缓存的 index.php 而不是 list 指定的 offline.html,尽管我在控制台中收到以下错误:

Application Cache Error event: Manifest fetch failed (-1) http://html5test.g1testserver/manifest.appcache

Firefox 仅显示“无法连接”对话框。下面列出了站点的布局和文件内容。

网站布局:

/root/
- manifest.appcache
- index.php
- offline.html
- .htaccess

list .app缓存:

CACHE MANIFEST
# version 3

CACHE:
offline.html

NETWORK:
index.php

FALLBACK:
/ offline.html

索引.php:

<?php
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
echo '<!DOCTYPE html>
<html manifest="/manifest.appcache">
<head>
<title>HTML5 Test</title>
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
</head>
<body>

<h1>This is index.php: '.date('d/m/Y H:i:s').'</h1>
</body>
</html>
';
?>

离线.html:

<!DOCTYPE html>
<html manifest="/manifest.appcache">
<head>
</head>
<body>
<h1>This will be served in place of index.php</h1>
</body>
</html>

.htaccess:

AddType text/cache-manifest .appcache

最佳答案

您不需要在 <html> 中包含 list 标签。只有当您想要缓存那个 页面时才需要这样做。不在文档类型中包含 list 并不意味着不会调用/更新 .appcache。

因此,如果您希望 offline.html 在 index.php 离线时作为回退运行,则不要缓存 index.php。

HTML5Rocks 有一些关于如何使用应用程序缓存的重要信息 here

关于html - 无法让 HTML5 AppCache 正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12476210/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com