delete unused files

This commit is contained in:
Daniel Bulant 2022-12-12 16:27:32 +01:00
parent 486b45c25c
commit 920072bfe0
5 changed files with 0 additions and 185 deletions

View file

@ -1,20 +0,0 @@
<script>
/**
* This file handles serviceworker registration
* To enable it, import it from another file, ie. src/pages/_layout.svelte
* ⚠ The imported component could get treeshaken if not used, eg. <SW />
* For configuring the serviceworker, refer to sw.js
*/
if ("serviceWorker" in navigator) {
import("workbox-window").then(async ({ Workbox }) => {
const wb = new Workbox("/serviceworker.js");
const registration = await wb.register();
// Reload the page if the PWA has been updated. Change strategy if needed.
wb.addEventListener("redundant", () => {
location.reload();
console.log("updated app");
});
});
}
</script>

View file

@ -1,51 +0,0 @@
import HMR from '@roxi/routify/hmr'
import App from './App.svelte';
import { logs } from './util/logs';
function display(formatted, type) {
const displayed = {
text: formatted,
type
};
logs.update(toDisplay => {
toDisplay.push(displayed);
return toDisplay;
});
if(type !== "error") {
setTimeout(() => {
logs.update(toDisplay => {
const i = toDisplay.indexOf(displayed);
toDisplay.splice(i, 1);
return toDisplay;
});
}, 1000);
}
}
const error = console.error.bind(console);
window.console.error = (...args) => {
error(...args);
args = args.map(arg => {
if(typeof arg === "string") return arg;
if(arg instanceof Error) return arg.message + "\n" + arg.stack;
return JSON.stringify(arg);
});
display(args.join("\n"), "error");
}
window.onerror = (event, SourceBuffer, line, col, error) => {
error(error);
display(error.message + "\n" + error.stack, "error");
}
// const log = console.log.bind(console);
// window.console.log = (...args) => {
// log(...args);
// display(JSON.stringify(args), "log");
//}
const app = HMR(App, { target: document.body }, 'routify-app')
export default app;

View file

@ -1,3 +0,0 @@
<script>
throw new Error("Shouldn't load");
</script>

View file

@ -1,3 +0,0 @@
export function load() {
throw new Error("Test error");
}

108
src/sw.js
View file

@ -1,108 +0,0 @@
// @ts-check
import { registerRoute, setDefaultHandler, setCatchHandler } from 'workbox-routing';
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies';
import { skipWaiting, clientsClaim } from 'workbox-core';
import { precacheAndRoute, matchPrecache } from 'workbox-precaching';
import { ExpirationPlugin } from 'workbox-expiration';
import { RoutifyPlugin, freshCacheData } from '@roxi/routify/workbox-plugin'
/**********
* CONFIG *
**********/
const entrypointUrl = '__app.html' // entrypoint
const fallbackImage = '404.svg'
const files = self.__WB_MANIFEST // files matching globDirectory and globPattern in rollup.config.js
const externalAssetsConfig = () => ({
cacheName: 'external',
plugins: [
RoutifyPlugin({
validFor: 60 // cache is considered fresh for n seconds.
}),
new ExpirationPlugin({
maxEntries: 50, // last used entries will be purged when we hit this limit
purgeOnQuotaError: true // purge external assets on quota error
})]
})
/**************
* INITIALIZE *
**************/
/**
* precache all files
* remember to precache __app.html and 404.svg if caching of all files is disabled
*/
precacheAndRoute(files)
/** precache only fallback files */
// precacheAndRoute(files.filter(file =>
// ['__app.html', '404.svg']
// .includes(file.url)
// ))
skipWaiting() // auto update service workers across all tabs when new release is available
clientsClaim() // take control of client without having to wait for refresh
/**
* manually upgrade service worker by sending a SKIP_WAITING message.
* (remember to disable skipWaiting() above)
*/
// addEventListener('message', event => { if (event.data && event.data.type === 'SKIP_WAITING') skipWaiting(); });
/**********
* ROUTES *
**********/
// serve local pages from the SPA entry point (__app.html)
registerRoute(isLocalPage, matchPrecache(entrypointUrl))
// serve local assets from cache first
registerRoute(isLocalAsset, new CacheFirst())
// serve external assets from cache if they're fresh
registerRoute(hasFreshCache, new CacheFirst(externalAssetsConfig()))
// serve external pages and assets
setDefaultHandler(new NetworkFirst(externalAssetsConfig()));
// serve a fallback for 404s if possible or respond with an error
setCatchHandler(async ({ event }) => {
switch (event.request.destination) {
case 'document':
return await matchPrecache(entrypointUrl)
case 'image':
return await matchPrecache(fallbackImage)
default:
return Response.error();
}
})
/**********
* CONDITIONS *
**********/
function isLocalAsset({ url, request }) { return url.host === self.location.host && request.destination != 'document' }
function isLocalPage({ url, request }) { return url.host === self.location.host && request.destination === 'document' }
function hasFreshCache(event) { return !!freshCacheData(event) }
/** Example condition */
function hasWitheringCache(event) {
const cache = freshCacheData(event)
if (cache) {
const { cachedAt, validFor, validLeft, validUntil } = cache
// return true if half the fresh time has passed
return validFor / 2 > validFor - validLeft
}
}