我正在运行一个 DHTML 页面并想缓存引用的 HTML、PHP 文件和 IMAGE 文件。
我在 WWW.sitename.COM/sub-dir/中有以下所有文件
.htaccess
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType text/cache-manifest .manifest
AddHandler server-parsed .html
AddHandler application/x-httpd-php .html .htm
缓存 list
CACHE MANIFEST
# Cache manifest version 0.0.00002
NETWORK:
CACHE:
http://WWW.sitename.COM/sub-dir/index.html
http://WWW.sitename.COM/sub-dir/this.php
http://WWW.sitename.COM/sub-dir/images/first.png
http://WWW.sitename.COM/sub-dir/images/second.png
FALLBACK:
THIS.PHP 文件中的 HTML list 引用...
<html manifest="http://WWW.sitename.COM/sub-dir/cache.manifest">
检测缓存事件的脚本
<script type="text/javascript">
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, false);
cache.addEventListener('obsolete', logEvent, false);
cache.addEventListener('progress', logEvent, false);
cache.addEventListener('updateready', logEvent, false);
function logEvent(e)
{
var online, status, type, message;
online = (navigator.onLine) ? 'yes' : 'no';
status = cacheStatusValues[cache.status];
type = e.type;
message = 'online: ' + online;
message+= ', event: ' + type;
message+= ', status: ' + status;
if (type == 'error' && navigator.onLine)
{
message+= ' (probably a syntax error in cache.manifest)';
}
console.log(message);
}
window.applicationCache.addEventListener(
'updateready',
function(){
window.applicationCache.swapCache();
console.log('swap cache has been called');
},
false
);
setInterval(function(){cache.update()}, 10000);
</script>
控制台报告未缓存任何内容。
非常感谢收到的任何和所有帮助。
谢谢。
最佳答案
经过大量研究,答案是...
不要包含包含
的页面的名称html list ="cache.manifest"
在 cache.manifest 文件中标记。
确保 cache.manifest 文件仅使用相对 URL 而不是绝对 URL。
确保您的 iPad 在任何系统软件更新后至少重新启动一次。
.htaccess 文件中 list 文件的正确 MIME 类型是
AddType text/cache-manifest .manifest
感谢 dev.bjorn.com/723 上的 Bjorn 帮助我实现目标……一篇值得一读的好博文。
关于html - iPad 上的应用程序缓存不会缓存网站数据或页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16002355/