开发者

Cache Manifest messes up my app when online

Gurus of SO

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

This is 开发者_如何学Can 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜