-
-
Save jakearchibald/4927b34bb14c3681a3c1c1ce6ede5b09 to your computer and use it in GitHub Desktop.
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
const url = new URL(location); | |
url.pathname += '.inc'; // just the content html | |
fetch(url).then(r => r.json()).then(data => { | |
document.querySelector('.content').innerHTML = data.html; | |
}); |
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
<!DOCTYPE html> | |
<h1>This is the static header</h1> | |
<div class="content"></div> | |
<script src="/app-v1.js"></script> |
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
self.addEventListener('install', event => { | |
event.waitUntil( | |
caches.open('static-v1').then(cache => | |
cache.addAll([ | |
'/shell-v1.html', | |
'/app-v1.js' | |
]) | |
) | |
); | |
}); | |
self.addEventListener('activate', event => { | |
// delete old caches | |
}); | |
self.addEventListener('fetch', event => { | |
const url = new URL(event.request.url); | |
if (url.origin == location.origin && url.pathname == '/') { | |
event.respondWith(caches.match('/shell-v1.html')); | |
return; | |
} | |
event.respondWith( | |
caches.match(event.request).then(r => r || fetch(event.request)) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment