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
import { Shadow, css } from './Shadow.js'; | |
import { useState } from './web_modules/preact/hooks.js'; | |
import { html } from '../web_modules/htm/preact.js'; | |
const styles = css` | |
h1 { color: red; } | |
`; |
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
elements.forEach((item) => { | |
item.shadowRoot.querySelector('expandable-item').removeAttribute('expanded'); | |
item.shadowRoot.querySelector('expandable-item').removeAttribute('transitioning'); | |
}); |
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
// cache only | |
self.addEventListener(‘fetch’, function(event) { | |
// If a match isn’t found in the cache, the response | |
// will look like a connection error | |
event.respondWith(caches.match(event.request)); | |
}); |
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
// network only | |
self.addEventListener(‘fetch’, function(event) { | |
event.respondWith(fetch(event.request)); | |
// or simply don’t call event.respondWith, which | |
// will result in default browser behaviour | |
}); |
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
// cache first | |
self.addEventListener(‘fetch’, function(event) { | |
event.respondWith( | |
caches.match(event.request).then(function(response) { | |
return response || fetch(event.request); | |
}) | |
); | |
}); |
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
// network first | |
self.addEventListener('fetch', function(event) { | |
event.respondWith( | |
fetch(event.request).catch(function() { | |
return caches.match(event.request); | |
}) | |
); | |
}); |
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('fetch', function(event) { | |
event.respondWith( | |
caches.open('my-app').then(function(cache) { | |
return cache.match(event.request).then(function(response) { | |
const fetchPromise = fetch(event.request).then(function(networkResponse) { | |
cache.put(event.request, networkResponse.clone()); | |
return networkResponse; | |
}) | |
return response || fetchPromise; | |
}) |
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
<script> | |
if ('serviceWorker' in navigator) { | |
window.addEventListener('load', () => { | |
navigator.serviceWorker.register('./sw.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(CACHENAME).then(cache => { | |
return cache.addAll([ | |
'./index.html', | |
'./main.4c088efe.js', | |
'./about.cd95a028.js', | |
'./contact.d0b533e7.js', | |
'./offline.eab917fd.js', | |
]); |
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('activate', event => { | |
event.waitUntil( | |
caches.keys().then(cacheNames => { | |
return Promise.all( | |
cacheNames | |
.filter(cacheName => cacheName.startsWith('my-cache-v') | |
&& cacheName !== CACHENAME) | |
.map(cacheName => caches.delete(cacheName)) | |
) | |
}) |
OlderNewer