![]() ExtendableEventĮxtends the lifetime of the install and activate events dispatched on the ServiceWorkerGlobalScope, as part of the service worker lifecycle. Represents a container for a list of Client objects the main way to access the active service worker clients at the current origin. A service worker client is either a document in a browser context or a SharedWorker, which is controlled by an active worker. Represents the scope of a service worker client. It provides a master directory of all the named caches that a ServiceWorker can access, and maintains a mapping of string names to corresponding Cache objects. Represents the storage for Cache objects. Represents the storage for Request / Response object pairs that are cached as part of the ServiceWorker life cycle. Reacting to push messages: Start up a service worker to send users a message to tell them new content is available.Background synchronization: Start up a service worker even when no users are at the site, so caches can be updated, etc.Interestingly, other specifications can and will start to make use of the service worker context, for example: In the future, service workers will be able to do a number of other useful things for the web platform that will bring it closer towards native app viability. Performance enhancements, for example pre-fetching resources that the user is likely to need in the near future, such as the next few pictures in a photo album.Custom templating based on certain URL patterns.Client-side compiling and dependency management of CoffeeScript, less, CJS/AMD modules, etc.Receiving centralized updates to expensive-to-calculate data such as geolocation or gyroscope, so multiple pages can make use of one set of data.Responding to resource requests from other origins.Service workers are also intended to be used for such things as: You can modify the response to these requests in any way you want, using the FetchEvent.respondWith() method. Your service worker can respond to requests using the FetchEvent event. The point where this event fires is generally a good time to clean up old caches and other things associated with the previous version of your service worker. You can listen for the install event a standard action is to prepare your service worker for usage when this fires, for example by creating a cache using the built in storage API, and placing assets inside it that you'll want for running your app offline. Activation can happen sooner using ServiceWorkerGlobalScope.skipWaiting() and existing pages can be claimed by the active worker using Clients.claim(). As soon as there are no more pages to be loaded, the new service worker activates (becoming the active worker). It is only activated when there are no longer any pages loaded that are still using the old service worker. If there is an existing service worker available, the new version is installed in the background, but not yet activated - at this point it is called the worker in waiting. If this is the first time a service worker has been made available, installation is attempted, then after a successful installation, it is activated. Installation is attempted when the downloaded file is found to be new - either different to an existing service worker (byte-wise compared), or the first service worker encountered for this page/site. An event is fired on the service worker and it hasn't been downloaded in the last 24 hours.A navigation to an in-scope page occurs.The service worker is immediately downloaded when a user first accesses a service worker–controlled site/page. In Firefox, service worker APIs are also hidden and cannot be used when the user is in private browsing mode.Īt this point, your service worker will observe the following lifecycle: Most significantly, HTTP connections are susceptible to malicious code injection by man in the middle attacks, and such attacks could be worse if allowed access to these powerful APIs. Service workers only run over HTTPS, for security reasons. ![]() Static import using the import statement is allowed. Service workers can't import JavaScript module dynamically, and import() will throw if it is called in a service worker global scope. ![]() It is designed to be fully async as a consequence, APIs such as synchronous XHR and Web Storage can't be used inside a service worker. It takes the form of a JavaScript file that can control the web-page/site that it is associated with, intercepting and modifying navigation and resource requests, and caching resources in a very granular fashion to give you complete control over how your app behaves in certain situations (the most obvious one being when the network is not available).Ī service worker is run in a worker context: it therefore has no DOM access, and runs on a different thread to the main JavaScript that powers your app, so it is non-blocking. ![]() A service worker is an event-driven worker registered against an origin and a path. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |