Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 281
brillout Avatar asked Oct 20 '11 23:10

brillout


People also ask

What is the advantage of application cache in HTML5?

HTML5 Cache Application cache gives an application three advantages: Offline browsing - users can use the application when they're offline. Speed - cached resources load faster Reduced server load - the. browser will only download updated/changed resources from the server.


2 Answers

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.

like image 126
Gene Vayngrib Avatar answered Oct 18 '22 09:10

Gene Vayngrib


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/

like image 30
brillout Avatar answered Oct 18 '22 10:10

brillout