2 questions about Service Workers

Good day, friends!

I couldn’t find the answers on Google, also can’t ask these questions on SO, I don’t think it’s the right format, and no answer on GitHub, so, sorry for bothering if it’s not the right format here either.

I recently started to learn PWA topic, specifically Service Workers. I went through MDN tutorial and since I code on Next.js I took “next-pwa” library and successfully implemented offline functionality. “next-pwa” updates the cache (with new assets) automatically after every rebuild.

My questions:

  1. Next.js allows to use ISR feature that incrementally updates static website (including new pages) without necessity to rebuild the website. Does the website need to be rebuilt in order for Service Worker to update the cache? Will there be a trade-off “ISR feature vs offline functionality”?

  2. The bigger the website the bigger the cache. Imagine the huge blog with million posts or e-commerce site with million items. Is there any data limit for caching? Are there any restrictions about what kind of websites are “allowed” or “not allowed” or partially “allowed” to cache (due to size)?

Technically no, there are no limits, it’s what space is available on the device. However in practice there are, and it’s dependent on browser/system. So for example (note I can’t guarantee the following haven’t changed) Chrome (and I assume all Chromium-based, so Edge as well) stores per-origin (ie everything from one place under one cache), and it provides an API you can use to check the estimated remaining storage for that, dunno limits though. Firefox has no limit but will start to spit warning messages out at about 50mb. Mobile Safari has a hard limit of 50mb.

Mobile browsers will naturally be a helluva lot more strict with limits, it’s assumed there is lot more free space and fewer performance concerns when a desktop browser is used.

Also, with service workers, the browser can wipe out the cache at any point, this is a deliberate design decision. So if the storage is filling up, the browser is likely to just blow the cache away.

So to go back to your question: yes in theory an entire huge site could be cached, but in practice that’s never going to happen, and the cache is going to be pretty small

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.