can-connect icon indicating copy to clipboard operation
can-connect copied to clipboard

Basic service worker support (on-demand fixtures) with tests

Open airhadoken opened this issue 10 years ago • 0 comments

This PR covers the use of Service Workers for managing data through can-connect. Service workers are a new technology that allows caching, indexing, and manipulation of data outside the scope of a page, via an installable script.

Service workers operate significantly differently from Web workers in that:

  • Service workers are shared between pages (Service Worker is a subtype of Shared Worker)
  • One service worker controls a set of pages in a scope, rather than one page controlling one or more SWs
  • The Service worker intercepts all fetch requests for the lifetime of the pages it controls, including the HTML itself and all resources loaded.

For SPA creators, the service worker is likely to manage all or a large percentage of resources, especially when dealing with offline access. Having support for the service worker in can-connect allows CanJS to be used more effectively in apps where a service worker is used.

In addition to support for service workers, this PR includes a simple service worker that caches fixtures on demand. when a resource is fixturized via connection.fixturize(), the SW will manipulate the resources for GET/PUT/POST/DELETE itself, without passing the request on to the HTTP host.

airhadoken avatar Jun 16 '15 21:06 airhadoken