【问题标题】:Problem While Doing html5 webapp cache做 html5 webapp 缓存时的问题
【发布时间】:2011-10-04 09:40:54
【问题描述】:

我有一个域名为http://draft.mo2do.com的webapp

当我访问 url 时,它将像下面的 url 一样解析并重定向到相应的站点主页

http://draft.mo2do.com/s/_91665/Home

这里我实现了离线缓存。我的 cache.manifest 文件如下

   CACHE MANIFEST
   # Offline cache v4.0

   # All other resources (e.g. sites) require the user to be online.  

   NETWORK:

   *

   # Additional resources to cache CACHE:

   # Add the pages in to the cache 

   /s/_91665/Home /s/_91665/CachedDraftBoard

   http://draft.mo2do.com

   # Add the images in to the cache 

   /s/store/-1/webapp/styles/webapp.css

   /s/store/-1/webapp/styles/nba_draft.css

   /s/store/-1/webapp/styles/add2drafthome.css?v2  

   #  Add the js files in to the cache 

   /s/store/-1/webapp/scripts/jquery-1.5.min.js

   /s/store/-1/webapp/scripts/iscroll.js

   /s/store/-1/webapp/scripts/webapp.js

   /s/store/-1/webapp/scripts/nba_draft.js

   /s/store/-1/webapp/scripts/cacheUpdate.js

   /s/store/-1/webapp/scripts/add2drafthome.js?v0.9.4  



   /webapp/icon.png /webapp/startup.png

   /s/store/-1/webapp/nba/addtodrafthome/arrow.png

   /s/store/-1/webapp/nba/addtodrafthome/close-bubble.png

   /s/store/-1/webapp/nba/addtodrafthome/icon.png

   /s/store/-1/webapp/nba/addtodrafthome/plus.png

   /s/store/-1/webapp/nba/addtodrafthome/share.png

   FALLBACK: 

   http://draft.mo2do.com

如果我直接访问站点 url,则缓存工作正常,那时我没有在缓存部分提及“http://draft.mo2do.com”。在此期间,离线缓存工作正常。

如果我只在浏览器中直接访问域网址“http://draft.mo2do.com”,则在离线模式下不会打开 404。

然后我在缓存部分添加了“http://draft.mo2do.com”,当时我遇到了异常

应用程序缓存进度事件 (2 of 3) http://draft.mo2do.com/ 应用程序缓存错误事件:资源获取失败 (-1) http://draft.mo2do.com/

如果我也访问域,它应该在离线模式下加载应用程序。如果我访问直接 url 应用程序加载正常。

我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery html manifest manifest.cache


    【解决方案1】:

    缓存必须直接引用特定资源,可以是 Javascript、CSS、HTML 页面、图像等等。从上面的内容我可以看出,你已经做到了。然而,简单地在其中放置一个域是行不通的(您还需要引用 所有 想要离线的页面,例如 /s/_91665/Home 需要在其中)。

    因此,沿线某处存在错误,但很难弄清楚您的意思:

    如果我只在浏览器中直接访问域网址“http://draft.mo2do.com”,则在离线模式下不会打开 404。

    你能说得清楚一点吗?您的意思是访问该 URL 会导致 404,还是页面本身存在错误?

    您确定您的缓存文件按预期运行吗? 如果您的缓存文件中有任何错误,您的离线应用程序根本无法运行。此页面提供了一些可能有帮助的调试代码:

    Debugging HTML 5 Offline Application Cache

    【讨论】:

    • 这是本地 url。我将通过在浏览器中输入“draft.mo2do.com”来启动我的 web 应用程序。当我访问该 url 时,它将重定向到 draft.mo2do.com/s/_91665/Home 这个 url 和我在缓存部分中提到的缓存页面。主页 url 正在被缓存,所以当我在离线模式下访问主页 url 时,它正在加载。但是“draft.mo2do.com”url 没有被缓存,我得到 404。如果我在缓存部分中添加了该 url,我收到资源获取失败错误。我需要的是当我访问域 url 时,它也应该从离线缓存中加载。
    猜你喜欢
    • 2012-08-01
    • 2012-06-03
    • 2011-01-04
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多