Просмотр исходного кода

feat(pwa): add sw.js and webmanifest

Tienson Qin 5 лет назад
Родитель
Сommit
dc187d9361
4 измененных файлов с 58 добавлено и 0 удалено
  1. 34 0
      public/sw.js
  2. BIN
      resources/img/logo-192x192.png
  3. BIN
      resources/img/logo-512x512.png
  4. 24 0
      resources/manifest.webmanifest

+ 34 - 0
public/sw.js

@@ -0,0 +1,34 @@
+if ('function' === typeof importScripts) {
+  importScripts('https://cdn.jsdelivr.net/npm/[email protected]/workbox/workbox-sw.min.js');
+  workbox.setConfig({modulePathPrefix: 'https://cdn.jsdelivr.net/npm/[email protected]/workbox/'});
+
+  const { core, precaching, routing, strategies, expiration } = workbox;
+  const { CacheFirst, NetworkFirst, NetworkOnly, StaleWhileRevalidate } = strategies;
+
+  workbox.routing.registerRoute(
+    ({request}) => request.destination === 'style' || request.destination === 'script',
+    new workbox.strategies.StaleWhileRevalidate({
+      cacheName: 'static',
+    })
+  );
+
+  workbox.routing.registerRoute(
+    /\/sw.js/,
+    new NetworkOnly()
+  );
+
+  workbox.routing.registerRoute(
+    /.*\.(?:png|jpg|jpeg|webp|svg|gif)/,
+    new workbox.strategies.CacheFirst({
+      cacheName: 'images',
+      plugins: [
+        new workbox.expiration.ExpirationPlugin({
+          maxEntries: 60,
+          maxAgeSeconds: 30 * 24 * 60 * 60,
+        })
+      ],
+    })
+  );
+
+  workbox.precaching.precacheAndRoute([{ url: "/", revision: "v1" }]);
+}

BIN
resources/img/logo-192x192.png


BIN
resources/img/logo-512x512.png


+ 24 - 0
resources/manifest.webmanifest

@@ -0,0 +1,24 @@
+{
+  "name": "Logseq",
+  "short_name": "Logseq",
+  "description": "A privacy-first, open-source platform for knowledge sharing and management.",
+  "icons": [
+    {
+      "src": "/static/img/logo-192x192.png",
+      "type": "image/png",
+      "sizes": "192x192"
+    },
+    {
+      "src": "/static/img/logo-512x512.png",
+      "type": "image/png",
+      "sizes": "512x512"
+    }
+  ],
+  "start_url": "/",
+  "scope": "/",
+  "background_color": "#002b36",
+  "theme_color": "#002b36",
+  "display": "standalone",
+  "orientation": "portrait-primary",
+  "lang": "en-US"
+}