Javascript Features
Service Workers
& Local storage
Browser support
Service Workers
Local Storage
Service Workers
It seems your browser does not support Service Workers, check the browser support above
If a browser does not support service workers you could inform the user about it, but not like: service workers are not supported. They don't have a clue about what a service worker is. You'll have to find a proper way to tell the user that their experience is not optimal.
You can also store the information in local storage that should be stored in the cache.
Local Storage
If local storage is not supported you can use a vanilla js based Polyfill or just push the data into an array
A vanilla js based Polyfill:
window.store = {
localStoreSupport: function() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
},
set: function(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else {
var expires = "";
}
if( this.localStoreSupport() ) {
localStorage.setItem(name, value);
}
else {
document.cookie = name+"="+value+expires+"; path=/";
}
},
get: function(name) {
if( this.localStoreSupport() ) {
ret = localStorage.getItem(name);
//console.log(typeof ret);
switch (ret) {
case 'true':
return true;
case 'false':
return false;
default:
return ret;
}
}
else {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {
ret = c.substring(nameEQ.length,c.length);
switch (ret) {
case 'true':
return true;
case 'false':
return false;
default:
return ret;
}
}
}
return null;
}
},
del: function(name) {
if( this.localStoreSupport() ) {
localStorage.removeItem(name);
}
else {
this.set(name,"",-1);
}
}
}
source