Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service worker cache vs HTTP cache

I disabled service workers in couple of production websites, I can see resource load time is better when using HTTP cache (from disk cache & from memory cache) than with service workers (from serviceworker) when I debug using Chrome devtools (Network tab).

I totally agree service workers gives better control over cache management and for offline usecase.

What other benefits Service worker has over HTTP cache ?

like image 846
tbnu Avatar asked Jul 22 '18 05:07

tbnu


People also ask

Does service worker work on HTTP?

Service Workers Require HTTPS Because Service Workers have so much power they are only enabled if the page is served using HTTPS. This ensures a level of security to allow the service worker to do the things it is designed to do.

Should I cache service worker?

It's not your responsibility to cache it. Adding a timestamp to the filename of your service-worker is an anti-pattern. According to the article on Service Worker Lifecycle, you should avoid changing the URL of your service worker script.

What is stored in HTTP cache?

Overview. The HTTP cache stores a response associated with a request and reuses the stored response for subsequent requests. There are several advantages to reusability. First, since there is no need to deliver the request to the origin server, then the closer the client and cache are, the faster the response will be.

What is service caching?

Caching is an optimization feature that can improve the performance of stateless services. When you enable caching for a service, Integration Server saves the entire contents of the pipeline after invoking the service in a local cache for the period of time that you specify.

What is the difference between service worker and HTTP caching?

When a cached resource is valid (<= 30 days): Service Worker returns the cached resource immediately without checking HTTP Caching. When a cached resource is expired (> 30 days): Service Worker passes the request to HTTP Caching, which directly passes the request to the remote servers.

What are the benefits of service worker caching?

In addition to fine-grained control of caching logic, service worker caching also provides: More memory and storage space for your origin: The browser allocates HTTP cache resources on a per- origin basis. In other words, if you have multiple subdomains, they all share the same HTTP cache.

How does a service worker check for cache?

Service Worker Cache: The Service Worker will check if the resource is in its Cache (either Cache Storage API or IndexedDB) based on the Service Worker’s caching strategies, and decides whether to return the resource directly. HTTP Cache will not be checked at this point.

What is the HTTP cache and how does it work?

The browser's HTTP cache is your first line of defense, but as you've learned, it's only really effective when loading versioned URLs that you've previously visited. On its own, the HTTP cache is not enough. Fortunately, two newer tools are available to help turn the tide in your favor: service workers and the Cache Storage API.


1 Answers

I have the same question. I observed that when service worker is enabled, the "Request to Service worker" takes much longer or equal to than downloading content. And overall http cache was much faster. I am not using the fully offline capability of PWA. Wondering if enabling service worker just for caching is harming performance instead of improving load time. I tried to dig into details by doing a performance audit and checking the communication between main thread and service worker thread, I am guessing it is the communication which is asynchronous in nature and hence takes more time.

like image 174
sh007 Avatar answered Nov 14 '22 23:11

sh007