Nachiketha shu Nachiketha shu - 1 year ago 127
Javascript Question

What is the storage limit for a service worker?

Most of the browsers provide localStorage with the storage limit of 5MB per domain.
Are there such memory limits/constraints with respect to service workers?

I know that web workers (on which service workers are based) don't have such limitations. But Web Workers are not exactly used for assets caching, instead they're used more for processing (so CPU is the main concern there).

If there's no limit on the memory size, could a badly designed website crash the browser?

Answer Source

Recently I came across this article: offline-cookbook which states as below:

Your origin is given a certain amount of free space to do what it wants with. That free space is shared between all origin storage: LocalStorage, IndexedDB, Filesystem, and of course Caches.

The amount you get isn't spec'd, it will differ depending on device and storage conditions. You can find out how much you've got via:

navigator.storageQuota.queryInfo("temporary").then(function(info) {
   // Result: <quota in bytes>
   // Result: <used data in bytes>

The above code might not work as it is in all the browsers. (for eg: in chrome<48 one might have to look for webkitPersistentStorage etc)

I didn't know that this memory allocation per domain is fixed for all types of storage.

For now this is the most relevant article/solution found for my problem. If anyone knows some better article or specifications please share.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download