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

前端 未结 7 1216
遥遥无期
遥遥无期 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: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.

提交回复
热议问题