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
if ('serviceWorker' in navigator) { | |
caches.keys().then(function(cacheNames) { | |
cacheNames.forEach(function(cacheName) { | |
caches.delete(cacheName); | |
}); | |
}); | |
} |
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
fetch(url, { | |
method: 'POST', | |
headers: { | |
'auth': '1234' | |
}, | |
body: JSON.stringify({ | |
name: 'dean', | |
login: 'dean', | |
}) | |
}) |
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
function successListener() { | |
var data = JSON.parse(this.responseText); | |
console.log(data); | |
} | |
function failureListener(err) { | |
console.log('Request failed', err); | |
} | |
var request = new XMLHttpRequest(); |
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
if (navigator.storage && navigator.storage.persist) { | |
navigator.storage.persist().then(granted => { | |
if (granted) { | |
alert("Storage will persist and not be cleared"); | |
} else { | |
alert("Storage won’t persist and may be cleared"); | |
} | |
}); | |
}; |
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> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Service Worker Toolbox</title> | |
</head> | |
<body> | |
<!-- Images --> | |
<img src="/images/contact.svg" height="80" width="80" /> | |
<img src="/images/info.svg" height="80" width="80" /> |
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
var image = document.getElementById('image'); | |
// Does the current browser support the API? | |
if (window.FaceDetector) { | |
var faceDetector = new FaceDetector(); | |
faceDetector.detect(image) | |
.then(faces => { | |
console.log(‘Faces found:’, faces.length); |
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
// Get all of the images that are marked up to lazy load | |
const images = document.querySelectorAll('.js-lazy-image'); | |
const config = { | |
// If the image gets within 50px in the Y axis, start the download. | |
rootMargin: '50px 0px', | |
threshold: 0.01 | |
}; | |
// The observer for the images on the page | |
let observer = new IntersectionObserver(onIntersection, config); |
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 cacheName = 'blogCache'; | |
const offlineUrl = '/offline/'; | |
self.addEventListener('install', event => { | |
event.waitUntil( | |
caches.open(cacheName) | |
.then(cache => cache.addAll([ | |
'./assets/font/icons.woff2', | |
'./assets/js/script.js', | |
'https://fonts.googleapis.com/css?family=Open+Sans:400,700', |
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
importScripts('workbox-sw.prod.v1.1.0.js'); | |
const workboxSW = new self.WorkboxSW(); | |
workboxSW.precache(fileManifest); | |
// The route for any requests from the googleapis origin | |
workboxSW.router.registerRoute('https://fonts.googleapis.com/(.*)', | |
workboxSW.strategies.cacheFirst({ | |
cacheName: 'googleapis', | |
cacheableResponse: { |
NewerOlder