workbox icon indicating copy to clipboard operation
workbox copied to clipboard

cache.add(precacheAndRoute) will block the main thread, such as network bandwidth?

Open mamumu123 opened this issue 1 year ago • 0 comments

Library Affected: _workbox-sw

Browser & Platform: Chrome

Issue or Feature Request Description: I thought it would request resources when the main thread is idle. 截屏2022-07-14 下午3 20 57

I have a very simple example here. example First of all, I copied this repo( https://github.com/mdn/sw-test ), it was very smooth. Next, I made some changes. I add 1000 pictures(or more) in 'cache.add', When reloading, then i found that the main thread is block.

截屏2022-07-15 上午9 30 37

+const lotList = [];
+for (let index = 1; index < 1000; index++) {
+  lotList.push(`/sw-test/gallery/${index}.jpg`);
+}
+
 const putInCache = async (request, response) => {
   const cache = await caches.open('v1');
   await cache.put(request, response);
@@ -69,6 +74,7 @@ self.addEventListener('install', (event) => {
       '/sw-test/gallery/bountyHunters.jpg',
       '/sw-test/gallery/myLittleVader.jpg',
       '/sw-test/gallery/snowTroopers.jpg',
+      ...lotList,
     ])
   );
 });

step: step1: add 1000 image, step2: tick ‘update on reload’ step3: reload Then, the above problem will recur

mamumu123 avatar Jul 15 '22 01:07 mamumu123