Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between using the Service Worker Cache API and regular browser cache?

In my Progressive Web App, should I be using the Cache API in a service worker for my static assets, or should I just rely on the browser's native cache control for these? What's the difference?

like image 844
Joe Marini Avatar asked Feb 04 '16 01:02

Joe Marini


People also ask

Should you cache the service worker?

Caching unnecessary resources wastes bandwidth and storage space and could cause your app to serve unintended outdated resources. You don't need to cache all the assets at once, you can cache assets many times during the lifecycle of your PWA, such as: On installation of the service worker. After the first page load.

What is service worker cache?

A service worker intercepts network-type HTTP requests and uses a caching strategy to determine what resources should be returned to the browser.

What is a service worker API?

Service workers essentially act as proxy servers that sit between web applications, the browser, and the network (when available).

What is API cache?

The Cache API is a system for storing and retrieving network requests and their corresponding responses. These might be regular requests and responses created in the course of running your application, or they could be created solely for the purpose of storing data for later use.


1 Answers

A major advantage of the service worker cache API is that it gives you more detailed control than the built-in browser cache does. For example, your service worker can cache multiple requests when the user first runs your web app, including assets that they have not yet visited. This will speed up subsequent requests. You can also implement your own cache control logic, ensuring that assets that are considered important are kept in the cache while deleting less-used data.

like image 101
Joe Marini Avatar answered Oct 14 '22 10:10

Joe Marini