HTML5 Cache — Is it possible to have several distinct caches for a single URL?

前端 未结 7 1214
遥遥无期
遥遥无期 2020-12-09 12:57

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 r

相关标签:
7条回答
  • 2020-12-09 13:20

    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

    0 讨论(0)
  • 2020-12-09 13:28

    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.

    0 讨论(0)
  • 2020-12-09 13:30

    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/

    0 讨论(0)
  • 2020-12-09 13:35

    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?

    0 讨论(0)
  • 2020-12-09 13:36

    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/

    0 讨论(0)
  • 2020-12-09 13:36

    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.

    0 讨论(0)
提交回复
热议问题