Question

Every URL can be linked to a single cache manifest. But I want several cache manifests linked to a same URL. Here is the reason:

Some files I want to be cached are rarely updated and large. So everytime the cache gets updated these large files get re-downloaded even though they may not have been changed. So I want to split up the cache. One cache for theses rarely updated large files and another cache for the often updated light files.

Do you guys have any idea how to split up an HTML5 cache?

Was it helpful?

Solution

The most efficient way is:

a) Use far-future expiration date (max-age) on all resources mentioned in manifest's CACHE section and add timestamp suffix to each file in the CACHE section, e.g.:

CACHE:
menu_1355817388000.js
toolbar_1355817389100.js

b) When any of the above files change on the server, regen/update manifest to change the timestamp. Only the file with the modified timestamp will get downloaded next time. Mission accomplished.

Note: Reload the page twice in the browser, as on the first refresh browser downloads just the manifest and uses old cached resources to paint the page. This is done to speed up displaying the page (there are tricks to handle this issue of double refresh, but they are outside the scope of your question)

See more info in this long but best article I ever seen on appcache.

OTHER TIPS

Use an iframe

Your page's cache manifest would include the light files and the cache manifest of an iframe loaded by this page would include the large files

On chrome the iframe's application cache will also be used for the page. I didn't tested this method on other browsers yet.

see a live example at http://www.timer-tab.com and if you are using chrome see its split up cache at chrome://appcache-internals/

When the manifest file is changed and the files of the application cache are downloaded again, the normal HTTP caching rules still apply. This means that if you set the correct HTTP caching headers for these large files, you'll get a 304 so these files are not downloaded again. So it's not necessary to split the application cache.

Maybe an answer but I'd more like to shed some light on my findings as a I troubleshoot my own webapp.

I've discovered that I can use 2 iframes (manifest_framework) and (manifest_media) to load the manifests, but i'm still not exactly clear how they are targetted, but I had limited success.

manifest_framework:

CACHE MANIFEST

CACHE:
appdata.ini
dialog.png
jquery.min.js
login.htm
login.js
manifest.appcache.js

NETWORK:
*

FALLBACK:

manifest_media:

CACHE MANIFEST

CACHE:
manifest_fwk.php
od/audio_track_1_1.m4a
od/audio_track_1_2.m4a
od/audio_track_1_3.m4a
od/audio_track_1_4.m4a
od/video_1.mp4
od/video_2.mp4
od/video_3.mp4

NETWORK:
*

FALLBACK:
./ webapp.php

./index.php is the page the 'landing page' which itself isn't cached but falls back to webapp.php when offline.

What I don't understand is how these link to the webapp.php page. I am finding I can only get access to one or the other manifests cache. The above works in mobile safari, the media would be cached, and image but not necessarily the JS or images in the framework manifest.

Anyone have more examples where multiple manifests are referenced from the one URL/page?

The W3C working group has abandoned the file system api, so it SHOULD NOT BE USED anymore.

We'll likely see it fall off the next version of Chrome.

http://www.w3.org/TR/file-system-api/

CACHE MANIFEST

# This is a comment.
# Cache manifest version 0.0.1
# If you change the version number in this comment,
# the cache manifest is no longer byte-for-byte
# identical.

demoimages/mypic.jpg
demoimages/yourpic.jpg
demoimages/ourpic.jpg
sr/scroll.js

NETWORK:
# All URLs that start with the following lines
# are whitelisted.
# whitelisted items are needed to help the site function, you could put regularly
# changing items here
http://example.com/examplepath/
http://www.example.org/otherexamplepath/

CACHE:
# Additional items to cache.
demoimages/allpics.jpg

FALLBACK:
demoimages/currentImg.jpg images/stockImage.jpg`

If the Iframe trick does not work, use the HTML5 FileSystem API

See http://updates.html5rocks.com/2012/04/Taking-an-Entire-Page-Offline-using-the-HTML5-FileSystem-API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top