Skip to content
View sw-04-fetching.js
function isHtmlRequest(request) {
return (
request.method === 'GET' &&
request.headers.get('accept').includes('text/html')
);
}
self.addEventListener('fetch', event => {
if (isHtmlRequest(event.request)) {
event.respondWith(
View sw-03-fetching.js
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
return response || fetch(event.request);
})
);
});
View sw-04-installation.js
var CACHE_VERSION = 1;
var CACHE_NAME = `example-4_${CACHE_VERSION}`;
var OFFLINE_URL = 'offline.html';
var CACHE_URLS = [
OFFLINE_URL
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
View sw-03-activation.js
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheName !== CACHE_NAME) {
console.log('Deleting out of date cache:', cacheName);
return caches.delete(cacheName);
}
})
View sw-03-installation.js
var CACHE_VERSION = 1;
var CACHE_NAME = `example-3_${CACHE_VERSION}`;
var CACHE_URLS = [
'site.css',
'site.js'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
View sw-02-service-worker.js
self.addEventListener('fetch', event => {
var response = new Response('This came from the service worker!');
event.respondWith(response);
// Default behavior - same as not using `respondWith`
// event.responseWith(fetch(event.request));
});
View sw-01-service-worker.js
console.log(self);
self.addEventListener('install', event => {
console.log('installed!', event);
});
self.addEventListener('activate', event => {
console.log('activated!', event);
});
View sw-01-registration.js
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
console.log('registered!', registration)
});
View keybase.md

Keybase proof

I hereby claim:

  • I am petebrowne on github.
  • I am petebrowne (https://keybase.io/petebrowne) on keybase.
  • I have a public key whose fingerprint is 7DD0 A89C 06AD F4F6 CFC1 AB45 B26F 34F6 A3E8 52DB

To claim this, I am signing this object:

View bem.scss
// BEM mixins for laying out modules.
// Based on:
//
// https://medium.com/@marcmintel/pushing-bem-to-the-next-level-with-sass-3-4-5239d2371321
$element-separator: '__' !default;
$modifier-separator: '--' !default;
// Creates a "block" in a BEM module.
//
Something went wrong with that request. Please try again.