Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Latest commit

 

History

History
18 lines (12 loc) · 1.13 KB

File metadata and controls

18 lines (12 loc) · 1.13 KB

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