Commit f311947b authored by cgm616's avatar cgm616

Send message to sw in app.js instead of fetch event

parent d6754918
......@@ -14,18 +14,22 @@ if ('serviceWorker' in navigator) {
window.onload = function() {
var x = document.getElementsByTagName("a");
var i;
for (i = 0; i < x.length; i++) {
console.log("iterating over is");
x[i].addEventListener("mouseenter", (function() {
console.log("link has been moused over");
var href = this.getAttribute("href");
if(href.substr(0,1) == '/') {
console.log("link is internal");
fetch(href);
for (i = 0; i < x.length; i++) {
var href = x[i].getAttribute("href");
if(href.substr(0,1) == '/' && href !== window.location.pathname) {
x[i].addEventListener("mouseenter", (function() {
if (!navigator.serviceWorker.controller) {
console.log("no controller");
return;
}
navigator.serviceWorker.controller.postMessage({
url: this.getAttribute('href'),
command: 'fetch'
});
}),
{ 'once': true, 'passive': true, }
);
}
}
}),{
'once': true,
'passive': true,
});
}
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment