41

Understanding Service Workers and Caching Strategies

 5 years ago
source link: https://www.tuicool.com/articles/hit/6VVRriU
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

If you have been in the javascript or development world for some time, you must have heard about Service Workers. So what are they? In simple and plain words, it’s a script that browser runs in the background and has whatsoever no relation with web pages or the DOM, and provide out of the box features . Some of these features are proxying network requests, push notifications and background sync. Service workers ensure that the user has a rich offline experience.

You can think of the service worker as someone who sits between the client and server and all the requests that are made to the server pass through the service worker. Basically, a middle man . Since all the request pass through the service worker, it is capable to intercept these requests on the fly.

yMjQrmq.png!webr6FrmqJ.png!web
Service Worker as the middle man:construction_worker:‍♂️

Service workers are like Javascript workers and have no interaction with the DOM or web pages. They run on a different thread and can access the DOM through the postMessage API. If you are planning on building, progressive web apps then you should possess a good understanding of the service workers and the caching strategies.

Note- Service workers are not web workers. Web workers are scripts that run on a different thread to perform load intensive calculations so that the main event loop is not blocked and does not cause a slow UI.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK