Skip to content

Commit

Permalink
Improve pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuepbach committed Sep 13, 2023
1 parent 500b422 commit dfed8b1
Show file tree
Hide file tree
Showing 126 changed files with 666 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="description" content="A self-hostable, realtime shopping list" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<link rel="icon" href="%sveltekit.assets%/icons/favicon.png" />
<meta name="viewport" content="width=device-width" />
<link rel="manifest" href="/manifest.json" />
%sveltekit.head%
Expand Down
62 changes: 62 additions & 0 deletions src/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// <reference types="@sveltejs/kit" />
import { build, files, version } from '$service-worker';

// Create a unique cache name for this deployment
const CACHE = `cache-${version}`;

const ASSETS = [
...build, // the app itself
...files // everything in `static`
];

self.addEventListener('install', (event) => {
// Create a new cache and add all files to it
async function addFilesToCache() {
const cache = await caches.open(CACHE);
await cache.addAll(ASSETS);
}

event.waitUntil(addFilesToCache());
});

self.addEventListener('activate', (event) => {
// Remove previous cached data from disk
async function deleteOldCaches() {
for (const key of await caches.keys()) {
if (key !== CACHE) await caches.delete(key);
}
}

event.waitUntil(deleteOldCaches());
});

self.addEventListener('fetch', (event) => {
// ignore POST requests etc
if (event.request.method !== 'GET') return;

async function respond() {
const url = new URL(event.request.url);
const cache = await caches.open(CACHE);

// `build`/`files` can always be served from the cache
if (ASSETS.includes(url.pathname)) {
return cache.match(url.pathname);
}

// for everything else, try the network first, but
// fall back to the cache if we're offline
try {
const response = await fetch(event.request);

if (response.status === 200) {
cache.put(event.request, response.clone());
}

return response;
} catch {
return cache.match(event.request);
}
}

event.respondWith(respond());
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/android/android-launchericon-48-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/android/android-launchericon-72-72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/android/android-launchericon-96-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added static/icons/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon-384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon-72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/167.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icons/ios/192.png
Binary file added static/icons/ios/20.png
Binary file added static/icons/ios/256.png
Binary file added static/icons/ios/29.png
Binary file added static/icons/ios/32.png
Binary file added static/icons/ios/40.png
Binary file added static/icons/ios/50.png
Binary file added static/icons/ios/512.png
Binary file added static/icons/ios/57.png
Binary file added static/icons/ios/58.png
Binary file added static/icons/ios/60.png
Binary file added static/icons/ios/64.png
Binary file added static/icons/ios/72.png
Binary file added static/icons/ios/76.png
Binary file added static/icons/ios/80.png
Binary file added static/icons/ios/87.png
Binary file added static/icons/windows11/LargeTile.scale-100.png
Binary file added static/icons/windows11/LargeTile.scale-125.png
Binary file added static/icons/windows11/LargeTile.scale-150.png
Binary file added static/icons/windows11/LargeTile.scale-200.png
Binary file added static/icons/windows11/LargeTile.scale-400.png
Binary file added static/icons/windows11/SmallTile.scale-100.png
Binary file added static/icons/windows11/SmallTile.scale-125.png
Binary file added static/icons/windows11/SmallTile.scale-150.png
Binary file added static/icons/windows11/SmallTile.scale-200.png
Binary file added static/icons/windows11/SmallTile.scale-400.png
Binary file added static/icons/windows11/SplashScreen.scale-100.png
Binary file added static/icons/windows11/SplashScreen.scale-125.png
Binary file added static/icons/windows11/SplashScreen.scale-200.png
Binary file added static/icons/windows11/SplashScreen.scale-400.png
Binary file added static/icons/windows11/Square44x44Logo.scale-100.png
Binary file added static/icons/windows11/Square44x44Logo.scale-125.png
Binary file added static/icons/windows11/Square44x44Logo.scale-150.png
Binary file added static/icons/windows11/Square44x44Logo.scale-200.png
Binary file added static/icons/windows11/StoreLogo.scale-100.png
Binary file added static/icons/windows11/StoreLogo.scale-125.png
Binary file added static/icons/windows11/StoreLogo.scale-150.png
Binary file added static/icons/windows11/StoreLogo.scale-200.png
Binary file added static/icons/windows11/StoreLogo.scale-400.png
Binary file removed static/logo-192.png
Diff not rendered.
Binary file removed static/logo-512.png
Diff not rendered.
Loading

0 comments on commit dfed8b1

Please sign in to comment.