IMPORTANT: Per accedir als fitxer de subversion: http://acacha.org/svn (sense password). Poc a poc s'aniran migrant els enllaços. Encara però funciona el subversion de la farga però no se sap fins quan... (usuari: prova i la paraula de pas 123456)

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:

http://caniuse.com/#feat=offline-apps

En canvi Service Workers encara està en progrés:

http://caniuse.com/#feat=serviceworkers

Inconvenients

douchebag: Someone who has surpassed the levels of jerk and asshole, however not yet reached fucker or motherfucker. Not to be confuzed with douche.
https://alistapart.com/article/application-cache-is-a-douchebag

Qüestions a tenir en compte

https://alistapart.com/article/application-cache-is-a-douchebag
  • 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.
  • GOTCHA #2: THE APPLICATIONCACHE ONLY UPDATES IF THE CONTENT OF THE MANIFEST ITSELF HAS CHANGED: HTTP already has a caching model. Each file can define how it should be cached. Even at a basic level, individual files can say “never cache me,” or “check with the server, it’ll tell you if there’s an update,” or “assume I’m good until 1st April 2022.” . However, imagine you had 50 html pages in your manifest. Each time you visit any of them while online, the browser would have to make 50 http requests to see if they need to be updated. As a slightly unusual workaround, the browser will only look for updates to files listed in the manifest if the manifest file itself has changed since the browser last checked. Any change that makes the manifest byte-for-byte different will do. This works pretty transparently for static assets which are ideally served via a content delivery network and never change. When the CSS/JavaScript/etc., changes it’s served under a different url, which means the content of the manifest changes. If you’re unfamiliar with far-future caching and CDNs, check out Yahoo!’s performance best-practice guide. Some resources cannot simply change their url like this, such as our HTML pages for instance. ApplicationCache won’t look for updates to these files without a friendly nudge. The simplest way to do this is to add a comment to your manifest and change that when necessary.
CACHE MANIFEST
# v1whatever.html

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

CACHE MANIFEST

  1. v1index.htmlNETWORK:

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 ?

<html manifest="example.appcache">
  ...
</html>

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:

CACHE MANIFEST
index.html
stylesheet.css
images/logo.png
scripts/main.js
http://cdn.example.com/scripts/main.js

Resources:

Vegeu també

Enllaços externs