serviceworker-cookbook/virtual-server
Salvador de la Puente González aec5556f89 Relying on html client rectangle for determining the iframe size 2016-09-17 18:01:25 +02:00
..
lib Renaming the recipe to Virtual Server 2015-11-25 23:09:45 +01:00
README.md Resolve #157 - Create sort order for sidebar 2015-12-10 09:58:29 -06:00
index.html Improved index page 2015-11-25 23:09:45 +01:00
index.js Relying on html client rectangle for determining the iframe size 2016-09-17 18:01:25 +02:00
service-worker.js Update eslint-config-airbnb to version 4 2016-01-23 12:23:47 +00:00

README.md

Virtual Server

This recipe shows a service worker acting like a remote server.

Difficulty

Intermediate

Use Case

As an application developer, I want to to fully decouple UI from business logic.

Solution

With REST APIs you can decouple client from business logic. The business logic is actually a separated component placed on a remote server. With Service Workers you can do the same. Simply move your business logic to a Service Worker responding on fetch events.

Instead of implementing your own logic to distinguish between routes and request methods, use ServiceWorkerWare or sw-toolbox' router feature to write your worker in a declarative way.

The client code is virtually identical to that in the API analytics recipe (the report link has been removed). On the contrary, the remote Express server has been completely replaced by the ServiceWorkerWare worker.

Category

Beyond Offline