shlogg · Early preview
Alish Giri @alishgiri

Creating A PWA With Svelte: A Step-by-Step Guide

Create a service-worker in src/service-worker/index.ts, add manifest.json to static/ with icons and screenshots, link it in app.html.

Step 1

Create a folder called service-worker inside src/ folder.

  
  
  Step 2

Create a new file called index.ts or index.js inside src/service-worker/ folder with the following contents.

/// <reference types="@sveltejs/kit" />
import { build, files, version } from '$service-worker';
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);...