forked from dauwhe/epub31-bff
-
Notifications
You must be signed in to change notification settings - Fork 3
Web Publication JS Behaviour
Hadrien Gardeur edited this page Oct 7, 2016
·
2 revisions
The current version of Web Publication JS (https://hadriengardeur.github.io/webpub-manifest/examples/MobyDick/webpub.js) does the following things:
- first, it checks if the browser has support for Service Workers
- if it does, a very basic Service Worker (https://hadriengardeur.github.io/webpub-manifest/examples/MobyDick/sw.js) is registered with a simple handler for fetch using a "network first then cache" policy
- once the Service Worker is ready, it sends a message to the console ("SW ready")
- it looks for a link in the current document (from which Web Publication JS was called) that matches a Web Publication Manifest (
rel="manifest"
andtype="application/webpub+json"
) - if such a link is available, it extracts the location of the manifest (
href
) and looks for the manifest in the cache (the cache name of each publication is the URI of its manifest)- if the manifest is stored in the cache, it displays a message in the console ("Found cache key") and does nothing more
- if the manifest is not stored in the cache, it extracts all the locations to resources listed in the
spine
(reading order of the publication) and inresources
(additional resources required to render the document) and stores them in the cache