File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,35 @@ function registerValidSW(swUrl, sendNotification) {
7373 ) ;
7474 }
7575 }
76+ } else if ( installingWorker . state === 'redundant' ) {
77+ if ( 'storage' in navigator && 'estimate' in navigator . storage ) {
78+ navigator . storage . estimate ( ) . then ( results => {
79+ const percentUsed = results . usage / results . quota * 100 ;
80+ // Let's assume that if we're using 95% of our quota, then this failure
81+ // was due to quota exceeded errors.
82+ // TODO: Hardcoding a threshold stinks.
83+ if ( percentUsed >= 0.95 ) {
84+ // Get rid of the existing SW so that we're not stuck
85+ // with the previously cached content.
86+ registration . unregister ( ) ;
87+
88+ // Let's assume that we have some way of doing this without inadvertantly
89+ // blowing away storage being used on the origin by something other than
90+ // our service worker.
91+ // I don't think that the Clear-Site-Data: header helps here, unfortunately.
92+ self . caches . keys ( ) . then ( names => {
93+ names . forEach ( name => {
94+ self . caches . delete ( name ) ;
95+ } ) ;
96+ } ) ;
97+
98+ // TODO clear indexeddb
99+ }
100+ } ) ;
101+ } else {
102+ // What about browsers that don't support navigator.storage.estimate()?
103+ // There's no way of guessing why the service worker is redundant.
104+ }
76105 }
77106 } ;
78107 } ;
You can’t perform that action at this time.
0 commit comments