Created
March 23, 2018 13:58
-
-
Save JeremieLitzler/1b9251d530726e435040de367b2a1cbc to your computer and use it in GitHub Desktop.
MWS ND 2018 - Service worker registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let appAlias = ""; | |
if (location.hostname === "localhost") { | |
appAlias = "/mws-restaurant-stage-1"; | |
} | |
function registerServiceWorker() { | |
if (!navigator.serviceWorker) { | |
console.log("ServiceWorker is not compatible with this browser..."); | |
return; | |
} | |
console.log("ServiceWorker is compatible with this browser!"); | |
navigator.serviceWorker.register("sw.js").then( | |
function(registration) { | |
// Registration was successful | |
console.log( | |
"ServiceWorker registration successful with scope: ", | |
registration.scope | |
); | |
}, | |
function(err) { | |
console.log("ServiceWorker registration failed: ", err); | |
} | |
); | |
} | |
window.addEventListener("load", function() { | |
//openDatabase(); | |
registerServiceWorker(); | |
let homeLinks = document.querySelectorAll(".jsHomeLink"); | |
for (const link of homeLinks) { | |
link.href = `${appAlias}`; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment