Coder Social home page Coder Social logo

awesome-service-worker's Introduction

Awesome Service Worker ๐Ÿ“ก

A curated list of useful resources for Service Worker

Service Workers are the backbone for creating offline-first applications. They sit, conceptually, between the network and the document, giving them the ability to intercept the network requests and provide content for documents, even while offline.

Inspired by the awesome list thing.

Table of Contents

Specification

W3C Specification -

Web Applications traditionally assume that the network is reachable ... HTML documents are loaded over HTTP and traditionally fetch all of their sub-resources via subsequent HTTP requests. This places web content at a disadvantage versus other technology stacks.

The service worker is designed first to redress this balance by providing a Web Worker context, which can be started by a runtime when navigations are about to occur. This event-driven worker is registered against an origin and a path (or pattern), meaning it can be consulted when navigations occur to that location. Events that correspond to network requests are dispatched to the worker and the responses generated by the worker may over-ride default network stack behavior. This puts the service worker, conceptually, between the network and a document renderer, allowing the service worker to provide content for documents, even while offline.

Support

ย  Chrome Firefox Safari IE Edge Opera Opera Mini Android Browser
Service Worker โœ…* โœ…* โŒ โŒ โŒ โœ…* โŒ โœ…*
Promises โœ… โœ… โœ… โŒ โœ… โœ… โŒ โœ…

Not full support yet | Last updated 7th July 2016

For up-to-date details on support see -

The API

Registering a Service Worker

Assuming the Service Worker file (called service-worker.js) is located in the root directory.

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register("/service-worker.js")
    .then(function(registration) {
      console.log('Registration succeeded!', registration);
    })
    .catch(function(err) {
      console.log('Registration failed!', err);
    });
}

See W3C Spec

The Service Worker Lifecycle

The Service Worker can be in one of the following states.

State Description
Parsed The Service Worker is downloaded and aprsed when the user first visits the page
Installing If the parsed file is new (or a different version of a previous file), installation is attempted
Installed / Waiting The Service Worker is installed and waiting to be activated
Activating The Service Worker is in the process of being activated
Activated The Service Worker is considered the active worker and has control of the document
Redundant When a new Service Worker has taken control of the page, the previous one is held as redundant

See W3C Spec

Service Worker Events

The Service Worker is event driven. There are four events it can listen for.

Event Description
install Dispatched when the service worker's installing worker changes
activate Dispatched when the service worker's active worker changes
fetch Dispatched when the document attempts a network (fetch) request
message Dispatched when the service worker receives a message, e.g. from the main document via the postMessage API

See W3C Spec

Articles

Videos

Talks

Tools

Chrome Dev Tools

The Service Worker for the current page can be viewed at Resources > Service Workers

You can also go to chrome://serviceworker-internals/ to see all registered Service Workers

Showcase

  • Service Worker Example Scripts ( Source ) - Various examples of things you can do with Service Workers (for example, precache, fetch handling, and versioning).

Licence

Licensed under the Creative Commons CC0 License.

awesome-service-worker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.