levymateus / sw

Service Worker fetch API caching proof of concept. Premise: save up requests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SW - Service worker [POC]

This is an proof of concept for service workers implentation.

This implementations is a list of countries get from a graphql API in the internet where the api call's using basiclly vanilla javascript, fetch API. The fetch calls are intercepted from service worker then saving up network requests.

Local run

Install using npm our yarn

  yarn install

Then you can run the project with:

  yarn dev

Then the server is hosted in http://localhost:8080

Conclusions

Open the devtools in your browser and select the network tab. In this tab can you see the api call's. The image below describes 2 calls, The first call is an network call (205ms) and the seconde an (ServieWorker) cached response (2ms).

network

In devtools Application tab you can observe the cached results like the image below:

cache

About

Service Worker fetch API caching proof of concept. Premise: save up requests.


Languages

Language:JavaScript 79.3%Language:HTML 15.7%Language:CSS 5.0%