Skip to content

Instantly share code, notes, and snippets.

@JeremieLitzler
Created March 23, 2018 13:58
Show Gist options
  • Save JeremieLitzler/1b9251d530726e435040de367b2a1cbc to your computer and use it in GitHub Desktop.
Save JeremieLitzler/1b9251d530726e435040de367b2a1cbc to your computer and use it in GitHub Desktop.
MWS ND 2018 - Service worker registration
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