gpt4 book ai didi

HTML5 离线 "Application Cache Error event: Manifest fetch failed (-1)"

转载 作者:技术小花猫 更新时间:2023-10-29 12:14:08 24 4
gpt4 key购买 nike

我正在尝试编写一个 HTML5 离线应用程序,但似乎无法让 Chrome 接受缓存 list 文件。

Chrome 在加载应用程序时将以下输出记录到其控制台:

Creating Application Cache with manifest http://localhost/cache.manifest
Application Cache Checking event
Application Cache Error event: Manifest fetch failed (-1) http://localhost/cache.manifest

但是,如果我从 list 文件中删除除第一行(即“CACHE MANIFEST”)以外的所有行,Chrome 会接受 list :

Creating Application Cache with manifest http://localhost/cache.manifest
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 0)
Application Cache Cached event

但是,只要我向 list 添加新行(即使下一行是空的),Chrome 就会恢复提示获取失败。

所有文件都通过 Python 在端口 80 上使用 SimpleHTTPServer 从 Windows 7 PC 本地提供。我已经使用以下行更新了 %PYTHON%/Lib/mimetypes.py 中的 types_map:

    '.manifest': 'text/cache-manifest',

list 应包含以下内容:

CACHE MANIFEST 
scripts/africa.js
scripts/main.js
scripts/offline.js
scripts/libs/raphael-min.js
favicon.ico
apple-touch-icon.png

最佳答案

要离线缓存网站 (HTML5),您需要指定其运行所需的所有文件。简而言之,指定所需的站点主要组件。

创建 list 的简单方法是在记事本中。

注意:CACHE MANIFEST 需要在第一行,您的文件将在一行空格之后,如下所示:

CACHE MANIFEST

Scripts/script.js
Content/Site.css
Scripts/jquery-ui-1.8.20.min.js
Scripts/modernizr-2.5.3.js
SESOL.png
Scripts/jquery.formatCurrency-1.4.0.min.js
http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css
http://code.jquery.com/jquery-1.8.2.min.js
http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js
Content/themes/images/icons-18-white.png
Controllers/AccountController
Controllers/HomeController
Models/AccountModels
Account/Login
Home/CheckOut

注2:删除每行后的所有空格。注意:3 您需要遵循确切的格式 FOLDER/File 或 FOLDER/FOLDER/FILE 等....

仅仅因为您有 list 文件并不意味着它会加载。您需要将以下内容添加到标签中:

<html manifest="~/cache.manifest" type="text/cache-manifest">

不要忘记,在您添加它之后,它会在页面第一次加载时被缓存。所以你需要在'mobileinit'事件中注册一个缓存事件。

$(document).on("mobileinit", function () {
//register event to cache site for offline use
cache = window.applicationCache;
cache.addEventListener('updateready', cacheUpdatereadyListener, false);
cache.addEventListener('error', cacheErrorListener, false);
function cacheUpdatereadyListener (){
window.applicationCache.update();
window.applicationCache.swapCache();
}
function cacheErrorListener() {
alert('site not availble offline')
}
}

下载 Safari 并使用网络检查器查找错误。 http://developer.apple.com/library/safari/#documentation/appleapplications/Conceptual/Safari_Developer_Guide/1Introduction/Introduction.html#//apple_ref/doc/uid/TP40007874-CH1-SW1

提示:Chrome 的开发者工具“F12”将向您显示 list 加载中的错误。即您仍然需要添加的文件。

希望这会有所帮助,涵盖整个过程。我假设如果您正处于开发的这个阶段,您将新添加这些到移动初始化:

$.mobile.allowCrossDomainPages = true; // cross domain page loading
$.mobile.phonegapNavigationEnabled = true; //Android enabled mobile
$.mobile.page.prototype.options.domCache = true; //page caching prefech rendering
$.support.touchOverflow = true; //Android enhanced scrolling
$.mobile.touchOverflowEnabled = true; // enhanced scrolling transition availible in iOS 5

Safari 开发者指南: https://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/Client-SideStorage/Client-SideStorage.html#//apple_ref/doc/uid/TP40002051-CH4-SW4

关于HTML5 离线 "Application Cache Error event: Manifest fetch failed (-1)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5727306/

24 4 0
文章推荐: linux - docker 容器大小远大于实际大小
文章推荐: html - 使用
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com