Skip to content

Commit

Permalink
correctly ignore things from older caches
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Sep 19, 2024
1 parent 5fbc13f commit d28403c
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 113 deletions.
6 changes: 4 additions & 2 deletions public/bento.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ async function registerServiceWorker() {
}
}
}
await registerServiceWorker()

registerServiceWorker()

if (navigator.userAgent.match(/18\.0 Safari/)) {
document.write(/*html*/ `
<p>
Expand All @@ -32,7 +34,7 @@ if (navigator.userAgent.match(/18\.0 Safari/)) {
no way to make <b>bento</b> work on Safari. 😭
</p>
`)
throw new (class SafariError extends Error {})("Safari")
throw new (class SafariError extends Error {})("safari")
}

import * as sounds from "./sounds/sounds.js"
Expand Down
223 changes: 112 additions & 111 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// update this when changing the service worker
const SERVICE_WORKER_VERSION = "v5"
const SERVICE_WORKER_VERSION = "v9"

const addResourcesToCache = async resources => {
const cache = await caches.open(SERVICE_WORKER_VERSION)
Expand All @@ -8,114 +8,114 @@ const addResourcesToCache = async resources => {

self.addEventListener("install", event => {
self.skipWaiting()
event.waitUntil(
addResourcesToCache([
// "/404.html",
// "/app.webmanifest",
// "/aux/apple-touch-icon.png",
// "/aux/fonts/font.ttf",
// "/aux/fonts/fs.woff",
// "/aux/fonts/iosevka-qp-light.ttf",
// "/aux/fonts/iosevka-qp-regular.ttf",
// "/aux/fonts/iosevka-rabbits-light.ttf"
// "/aux/fonts/iosevka-rabbits-regular.ttf",
// "/aux/icons/bento-monochrome.png",
// "/aux/icons/bento.svg",
// "/aux/icons/maskable_icon.png",
// "/aux/iphone-silence.flac",
// "/aux/kits/casio/a.flac",
// "/aux/kits/casio/b.flac",
// "/aux/kits/casio/c.flac",
// "/aux/kits/casio/d.flac"
// "/bento.js",
// "/convenience/extend-native-prototypes.js",
// "/convenience/loop.js",
// "/db/db.js",
// "/db/db.worker.js",
// "/db/share.js",
// "/elements/base.js",
// "/elements/bento-elements.js",
// "/elements/box.css",
// "/elements/box.js",
// "/elements/control-strip.css",
// "/elements/controls/button.css",
// "/elements/controls/button.js",
// "/elements/controls/control.js",
// "/elements/controls/controls.js",
// "/elements/controls/flip.css",
// "/elements/controls/layer-type-selector.css",
// "/elements/controls/loop-selector.css",
// "/elements/controls/popout-grid.css",
// "/elements/controls/popout.css",
// "/elements/controls/popout.js",
// "/elements/controls/record.css",
// "/elements/controls/speed-selector.css",
// "/elements/grid-controls.css",
// "/elements/grid-controls.js",
// "/elements/grid-selector.css",
// "/elements/grid-selector.js",
// "/elements/grid.css",
// "/elements/grid.js",
// "/elements/layer-options.css",
// "/elements/layer-selector-choice.css",
// "/elements/layer-selector-choice.js",
// "/elements/layer-selector.css",
// "/elements/layer-selector.js",
// "/elements/machine.js",
// "/elements/master-controls.css",
// "/elements/master-controls.js",
// "/elements/minigrid.css",
// "/elements/minigrid.js",
// "/elements/nav.css",
// "/elements/nav.js",
// "/elements/party.js",
// "/elements/screen-controls.css",
// "/elements/screen-controls.js",
// "/elements/screen-selector.css",
// "/elements/screen-selector.js",
// "/elements/screen.css",
// "/elements/screen.js",
// "/elements/settings.css",
// "/elements/settings.js",
// "/elements/tape.css",
// "/elements/tape.js",
// "/favicon.ico",
// "/graphics/constants.js",
// "/graphics/graphics.js",
// "/graphics/graphics.worker.js",
// "/icons.js",
// "/index.html",
// "/info.html",
// "/io/ask.js",
// "/io/data-transfer.js",
// "/io/modmask.js",
// "/log.text",
// "/loop.js",
// "/memory/constants.js",
// "/memory/convert.js",
// "/memory/memory.js",
// "/memory/migrations.js",
// "/memory/tree/grid.js",
// "/memory/tree/layer.js",
// "/memory/tree/sound.js",
// "/memory/tree/step.js",
// "/memory/tree/tree.js",
// "/sounds/effects/delay.js",
// "/sounds/effects/dj-filter.js",
// "/sounds/effects/effect.js",
// "/sounds/node.js",
// "/sounds/quietparty.audioworklet.js",
// "/sounds/quietparty.js",
// "/sounds/sampler.audioworklet.js",
// "/sounds/scale.js",
// "/sounds/sounds.js",
// "/sounds/sources/passthru.js",
// "/sounds/sources/source.js",
// "/sounds/sources/synth.js",
// "/sounds/transport.audioworklet.js",
// "/stylesheet.css"
])
)
// event.waitUntil(
// addResourcesToCache([
// "/404.html",
// "/app.webmanifest",
// "/aux/apple-touch-icon.png",
// "/aux/fonts/font.ttf",
// "/aux/fonts/fs.woff",
// "/aux/fonts/iosevka-qp-light.ttf",
// "/aux/fonts/iosevka-qp-regular.ttf",
// "/aux/fonts/iosevka-rabbits-light.ttf"
// "/aux/fonts/iosevka-rabbits-regular.ttf",
// "/aux/icons/bento-monochrome.png",
// "/aux/icons/bento.svg",
// "/aux/icons/maskable_icon.png",
// "/aux/iphone-silence.flac",
// "/aux/kits/casio/a.flac",
// "/aux/kits/casio/b.flac",
// "/aux/kits/casio/c.flac",
// "/aux/kits/casio/d.flac"
// "/bento.js",
// "/convenience/extend-native-prototypes.js",
// "/convenience/loop.js",
// "/db/db.js",
// "/db/db.worker.js",
// "/db/share.js",
// "/elements/base.js",
// "/elements/bento-elements.js",
// "/elements/box.css",
// "/elements/box.js",
// "/elements/control-strip.css",
// "/elements/controls/button.css",
// "/elements/controls/button.js",
// "/elements/controls/control.js",
// "/elements/controls/controls.js",
// "/elements/controls/flip.css",
// "/elements/controls/layer-type-selector.css",
// "/elements/controls/loop-selector.css",
// "/elements/controls/popout-grid.css",
// "/elements/controls/popout.css",
// "/elements/controls/popout.js",
// "/elements/controls/record.css",
// "/elements/controls/speed-selector.css",
// "/elements/grid-controls.css",
// "/elements/grid-controls.js",
// "/elements/grid-selector.css",
// "/elements/grid-selector.js",
// "/elements/grid.css",
// "/elements/grid.js",
// "/elements/layer-options.css",
// "/elements/layer-selector-choice.css",
// "/elements/layer-selector-choice.js",
// "/elements/layer-selector.css",
// "/elements/layer-selector.js",
// "/elements/machine.js",
// "/elements/master-controls.css",
// "/elements/master-controls.js",
// "/elements/minigrid.css",
// "/elements/minigrid.js",
// "/elements/nav.css",
// "/elements/nav.js",
// "/elements/party.js",
// "/elements/screen-controls.css",
// "/elements/screen-controls.js",
// "/elements/screen-selector.css",
// "/elements/screen-selector.js",
// "/elements/screen.css",
// "/elements/screen.js",
// "/elements/settings.css",
// "/elements/settings.js",
// "/elements/tape.css",
// "/elements/tape.js",
// "/favicon.ico",
// "/graphics/constants.js",
// "/graphics/graphics.js",
// "/graphics/graphics.worker.js",
// "/icons.js",
// "/index.html",
// "/info.html",
// "/io/ask.js",
// "/io/data-transfer.js",
// "/io/modmask.js",
// "/log.text",
// "/loop.js",
// "/memory/constants.js",
// "/memory/convert.js",
// "/memory/memory.js",
// "/memory/migrations.js",
// "/memory/tree/grid.js",
// "/memory/tree/layer.js",
// "/memory/tree/sound.js",
// "/memory/tree/step.js",
// "/memory/tree/tree.js",
// "/sounds/effects/delay.js",
// "/sounds/effects/dj-filter.js",
// "/sounds/effects/effect.js",
// "/sounds/node.js",
// "/sounds/quietparty.audioworklet.js",
// "/sounds/quietparty.js",
// "/sounds/sampler.audioworklet.js",
// "/sounds/scale.js",
// "/sounds/sounds.js",
// "/sounds/sources/passthru.js",
// "/sounds/sources/source.js",
// "/sounds/sources/synth.js",
// "/sounds/transport.audioworklet.js",
// "/stylesheet.css"
// ])
// )
})

const putInCache = async (request, response) => {
Expand All @@ -124,7 +124,8 @@ const putInCache = async (request, response) => {
}

const cacheFirst = async ({request, preloadResponsePromise = null}) => {
const responseFromCache = await caches.match(request)
const cache = await caches.open(SERVICE_WORKER_VERSION)
const responseFromCache = await cache.match(request)
if (responseFromCache) {
return responseFromCache
}
Expand All @@ -137,7 +138,7 @@ const cacheFirst = async ({request, preloadResponsePromise = null}) => {

try {
const responseFromNetwork = await fetch(request)
if (responseFromNetwork.ok) {
if (responseFromNetwork.status == 200) {
putInCache(request, responseFromNetwork.clone())
}
return responseFromNetwork
Expand Down

0 comments on commit d28403c

Please sign in to comment.