Search code examples
htmlcachinghtml5-appcachecache-manifest

HTML5 AppCache: Can somebody explain purpose of NETWORK section in manifest file?


I have gone through html5rocks, mozilla developer doc. Those definitions are very confusing. Can anybody explain this in simple terms ?

I am not sure why do we even need NETWORK section in appcache manifest file. I think it is as good as not having entry in CACHE section.

NETWORK Mozilla:

Files listed under the NETWORK: section header in the cache manifest file are white-listed resources that require a connection to the server. All requests to such resources bypass the cache, even if the user is offline. The wildcard character * can be used once. Most sites need *.

NETWORK HTML5Rocks:

Files listed in this section may come from the network if they aren't in the cache, otherwise the network isn't used, even if the user is online. You can white-list specific URLs here, or simply "", which allows all URLs. Most sites need "".


Solution

  • NETWORK: are resources that requires the user to be online.

    From http://www.html5rocks.com/en/tutorials/appcache/beginner/

    NETWORK:

    Files listed in this section may come from the network if they aren't in the cache, otherwise the network isn't used, even if the user is online. You can white-list specific URLs here, or simply "*", which allows all URLs. Most sites need "*".

    General practice is to define what resources should be cached using the CACHE section, and then use NETWORK section with * wildcard to default all other resources to require the user to be online.

    Example:

     CACHE:
     # These resources will be downloaded once to be cached  on the client.
     # After they are cached, even if the user has a network connection,
     # they will not re-download these resources, but instead use their local
     # cached copies instead.
    
     /favicon.ico
     /index.html
     /images/banner.html
    
     # This section will explicitly tell the client "every other resource"
     # requires a network connection.
     NETWORK:
     *
    

    So why would you explicitly tell the client that every other resource requires a network connection?

    http://alistapart.com/article/application-cache-is-a-douchebag#section7 Gotcha #5 will explain that.

    If you cache index.html but not cat.jpg, that image will not display on index.html even if you’re online.

    And you can see their demo here: http://appcache-demo.s3-website-us-east-1.amazonaws.com/without-network/