HTML5 Cache Manifest: Fallback section & Network *

Jiew Meng picture Jiew Meng · Jul 19, 2010 · Viewed 14.8k times · Source

from Dive into HTML5: Cache Manifest: Fallback section

CACHE MANIFEST
FALLBACK:
/ /offline.html
NETWORK:
*

i dont understand from the URL given what this block of code exactly does. does the fallback section mean when anything is not found, show the offline.html page

then network: * all resources will be cached? it says also

It uses common CSS, JavaScript, and images on each page. Each of these resources would need to be listed explicitly in the CACHE

this seems to conflict to network: * where it seems to say cache everything?

Answer

aiham picture aiham · Jan 13, 2011

There are three types of headings in a cache manifest, CACHE, NETWORK and FALLBACK. Anything that is not under a heading is implicitly set under CACHE. An explanation of each section:

CACHE: Files under this heading will be cached.

NETWORK: Files under this heading require an internet connection and so will be NOT be cached.

FALLBACK: Files matched by patterns under this heading (Such as the pattern "/", which matches all files) and have not been cached, will have a fallback file shown instead.

With regards to the block of code from Dive into HTML 5, there is an explanation of the "NETWORK: *" part just under it:

It means that, while you’re browsing this hypothetical offline-enabled Wikipedia online, your browser will fetch images and videos and other embedded resources normally, even if they are on a different domain. (This is common in large websites, even if they aren’t part of an offline web application. HTML pages are generated and served locally, while images and videos are served from a CDN on another domain.) Without this wildcard flag, our hypothetical offline-enabled Wikipedia would behave strangely when you were online — specifically, it wouldn’t load any externally-hosted images or videos!

The following quote:

It uses common CSS, JavaScript, and images on each page. Each of these resources would need to be listed explicitly in the CACHE

means that you must include all necessary CSS, Javascript and image files in the manifest under the CACHE heading. It does not conflict with 'NETWORK: *' because the NETWORK heading does NOT mean 'cache everything'. It actually means the opposite: that everything under the NETWORK heading requires an internet connection and should not be cached.