aka Application Cache/Cache Manifest
AppCache is a high-level, declarative API, with which you specify the set of resources you'd like the browser to cache;
Vegeu com possible alternativa Cache API i Service Workers
IMPORTANT: està deprecated/obsolet! https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache
Però molt suportat:
En canvi Service Workers encara està en progrés:
douchebag: Someone who has surpassed the levels of jerk and asshole, however not yet reached fucker or motherfucker. Not to be confuzed with douche.
Qüestions a tenir en compte
- GOTCHA 0: Concepte de manifest, un fitxer que indica tots els assets que utilitzar la web app.
- GOTCHA #1: FILES ALWAYS COME FROM THE APPLICATIONCACHE, EVEN IF YOU’RE ONLINE: When you visit a page with OfflineSupport, you’ll instantly get the version from your cache. Once the page has finished rendering, the browser will look for updates to the manifest and cached files. This sounds like a bizarre way of doing things, but it means the browser doesn’t have to wait for connections to time out before deciding you’re offline. The ApplicationCache fires an updateready event to let us know there’s updated content, but we can’t simply refresh the page at this point, because the user may have already interacted with the version they already have. This isn’t a big deal here, because the old version is probably good enough. If need be, we can display a little “An update is available. Refresh to update” message. You may have seen this on Google apps such as Reader and Gmail.
Comments start with # in manifests. If I update whatever.html I’d change my comment to # v2, triggering an update. You could automate this by having a build script output something similar to ETAGs for each file in the manifest as a comment, so each file change is certain to change the content of the manifest.
However, updating the text in the manifest doesn’t guarantee the resources within will be updated from the server.
- GOTCHA #3: THE APPLICATIONCACHE IS AN ADDITIONAL CACHE, NOT AT ALTERNATIVE ONE: When the browser updates the ApplicationCache, it requests urls as it usually would. It obeys regular caching instructions: If an item’s header says “assume I’m good until 1st April 2022” the browser will assume that resource is indeed good until 1st April 2022, and won’t trouble the server for an update. This is a good thing, because you can use it to cut down the number of requests the browser needs to make when the manifest changes. This can catch people out while they’re experimenting if their servers don’t serve cache headers. Without specifics, the browser will take a guess at the caching. You could update whatever.html and the manifest, but the browser won’t update the file because it’ll “guess” that it doesn’t need updating. All files you serve should have cache headers and this is especially important for everything in your manifest and the manifest itself. If a file is very likely to update, it should be served with no-cache. If the file changes infrequently must-revalidate is a better bet. For example, must-revalidate is a good choice for the manifest file itself. Oh, while we’re on the subject…
- GOTCHA #4: NEVER EVER EVER FAR-FUTURE CACHE THE MANIFEST: You might think you can treat your manifest as a static file, as in “assume I’m good until 1st April 2022,” then change the url to the manifest when you need to make updates. No! Don’t do that! *slap* Remember Gotcha #1: When the user visits a page a second time they’ll get the ApplicationCached version. If you’ve changed the url to the manifest, bad luck, the user’s cached version still points at the old manifest, which is obviously byte-for-byte the same so nothing updates, ever.
- GOTCHA #5: NON-CACHED RESOURCES WILL NOT LOAD ON A CACHED PAGE: If you cache index.html but not cat.jpg, that image will not display on index.html even if you’re online. No, really, that’s intended behaviour, see for yourself. To disable this behaviour, use the NETWORK section of the manifest
The * indicates that the browser should allow all connections to non-cached resources from a cached page. Here, you can see it applied to the previous example. Obviously, these connections will still fail while offline.
Well done; you made it through the simple playing-to-its-strengths ApplicationCache example. Yes, really, that’s the simple case. Sorry. Let’s try something a bit tougher.
Com funciona ?
S'ha d'utilitzar? el mime-type text/cache-manifest. You may need to add a custom file type to your web server or .htaccess configuration, for example, to serve this mime-type in Apache, add this line to your config file:
AddType text/cache-manifest .appcache
Structure of a manifest file: