在线时缓存清单弄乱了我的应用程序

发布于 2024-12-06 15:23:01 字数 388 浏览 2 评论 0原文

SO 的大师

我正在尝试使用 CACHE MANIFEST/HTML5。我的应用程序是 JS 重的并且基于 jquery/jquerymobile 构建。

这是我的清单的摘录,

CACHE MANIFEST
FALLBACK:
/
NETWORK:
*
CACHE:
/css/style.css
/js/jquery.js

但不知何故,该应用程序在第一次时不会加载文件,整个应用程序崩溃了。

  • 难道是我的格式不对?
  • 我不应该将 JS 加载到缓存中吗?
  • 如果有任何内容不可用,我应该如何以不同的方式对待这个问题,以便始终首先检查网络,并且只加载缓存中可用的内容?

谢谢。

Gurus of SO

I am trying to play with CACHE MANIFEST/HTML5. My app is JS heavy and built on jquery/jquerymobile.

This is an excerpt of what my Manifest looks like

CACHE MANIFEST
FALLBACK:
/
NETWORK:
*
CACHE:
/css/style.css
/js/jquery.js

But somehow, the app doesn't load the files the first time itself and the entire app breaks down.

  • Is my format wrong?
  • Should I never load JS into the Cache?
  • How should I treat this differently to always check the network first if anything isn't available and only load stuff available from the Cache?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撑一把青伞 2024-12-13 15:23:01

我尝试了一个带有缓存清单的简单页面,它对我来说效果很好,所以我不太确定问题是什么。但是,

  1. 是的,格式有问题。 FALLBACK 部分中的条目需要有两部分:模式和 URL。这表示“如果任何与该模式匹配的页面无法离线使用,则显示 URL(将被缓存)”。主要的例子(如此处所示)是“/ /offline.html”,这意味着“for所有页面,如果我们处于离线状态且未缓存,则显示 /offline.html。”但是,我不认为这是问题的根源,因为我用您的确切清单对其进行了测试,并且它仍然有效。
  2. JS 文件没有什么特别的。将它们加载到缓存中应该没问题。
  3. 我不明白第三个问题。这里可能有两个目标:a) 在返回缓存之前,如何首先检查是否有在线可用的较新版本的文件;b) 如何检查网络以查看是否有更新版本的文件未缓存的文件,如果我们处于离线状态,则会返回到错误页面。 (a) 的答案是,一旦打开缓存清单,事情的工作方式就会非常不同。它永远不会检查文件的新版本,除非清单也有新版本。因此,每当更改任何文件时,您都必须始终更新清单。 (b) 的答案是 FALLBACK 部分。

请参阅深入了解 HTML5 关于此内容的精彩章节,特别是“调试的艺术,又名“”杀了我!现在就杀了我!”这解释了清单的更新方式。

另外,我认为我们还没有解决您问题的实质,因为不清楚您所说的“应用程序本身不会第一次加载文件”是什么意思。哪些文件不加载?刷新后它们加载正常吗? ETC。

I tried a simple page with your cache manifest and it worked fine for me, so I'm not really sure what the problem is. But,

  1. Yes, there is something wrong with the format. The entries in the FALLBACK section need to have two parts: a pattern, and a URL. This says "if any page matching the pattern is not available offline, display the URL instead (which will be cached)." The main example of this (as shown here) is "/ /offline.html", which means "for all pages, if we are offline and they are not cached, display /offline.html instead." However, I don't think this is the source of your problem since I tested it with your exact manifest and it still worked.
  2. There is nothing special about JS files. It should be fine to load them into the cache.
  3. I don't understand the third question. There are possibly two goals here: a) how do you check to see if there is a newer version of the file available online first, before going back to the cache, and b) how do you check the network to see if there is a file that is not cached, and if we are offline, fall back to an error page. The answer to (a) is that once you have turned on the cache manifest, things work very differently. It will never check for new versions of the files unless there is a new version of the manifest also. So you must always update the manifest whenever you change any files. The answer to (b) is the FALLBACK section.

See Dive Into HTML5's excellent chapter on this, particularly the section "The fine art of debugging, a.k.a. “Kill me! Kill me now!”" which explains how the manifest updates.

Also I don't think we've gotten to the meat of your question, because it's unclear what you mean by "the app doesn't load the files the first time itself". Which files don't load? Do they load properly after a refresh? Etc.

淡忘如思 2024-12-13 15:23:01

我让它刷新缓存的唯一方法是使用提交号或时间戳重命名清单文件,并将缓存声明更改为

我将这部分作为我的构建的一部分。

The only way I got this to work to refresh a cache was to rename the manifest file with a commit number or timestamp, and change the cache declaration to

<html manifest='mymanifest382330.manifest'>

I made this part of my build.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文