Browse Source

add offline pwa support

AykutSarac 3 years ago
parent
commit
6647e9efa1
6 changed files with 50 additions and 4 deletions
  1. 2 1
      next.config.js
  2. 36 0
      public/fallback-development.js
  3. 2 1
      public/manifest.json
  4. 10 2
      public/sw.js
  5. 0 0
      public/sw.js.map
  6. 0 0
      src/pages/_offline.tsx

+ 2 - 1
next.config.js

@@ -7,12 +7,13 @@ const nextConfig = {
   reactStrictMode: true,
   exportPathMap: () => ({
     "/": { page: "/" },
-    "/editor": { page: "/editor" },
+    "/editor": { page: "/_offline" },
   }),
   compiler: {
     styledComponents: true,
   },
   pwa: {
+    disable: process.env.NODE_ENV === "development",
     dest: "public",
     register: true,
   },

+ 36 - 0
public/fallback-development.js

@@ -0,0 +1,36 @@
+/******/ (() => { // webpackBootstrap
+/******/ 	"use strict";
+var __webpack_exports__ = {};
+
+
+self.fallback = async request => {
+  // https://developer.mozilla.org/en-US/docs/Web/API/RequestDestination
+  switch (request.destination) {
+    case 'document':
+      if (true) return caches.match("/_offline", {
+        ignoreSearch: true
+      });
+
+    case 'image':
+      if (false) {}
+
+    case 'audio':
+      if (false) {}
+
+    case 'video':
+      if (false) {}
+
+    case 'font':
+      if (false) {}
+
+    case '':
+      if (false) {}
+
+    default:
+      return Response.error();
+  }
+
+  ;
+};
+/******/ })()
+;

+ 2 - 1
public/manifest.json

@@ -1,11 +1,12 @@
 {
   "name": "JSON Visio",
   "short_name": "JSON Visio",
+  "description": "Visualize your JSON data onto graphs seamlessly.",
   "theme_color": "#36393e",
   "background_color": "#36393e",
   "display": "standalone",
   "orientation": "landscape",
-  "scope": "/",
+  "scope": "/editor",
   "start_url": "/editor",
   "icons": [
     {

+ 10 - 2
public/sw.js

@@ -81,7 +81,7 @@ define(['./workbox-74d02f44'], (function (workbox) { 'use strict';
   * See https://goo.gl/2aRDsh
   */
 
-  importScripts();
+  importScripts("fallback-development.js");
   self.skipWaiting();
   workbox.clientsClaim();
   workbox.registerRoute("/", new workbox.NetworkFirst({
@@ -103,11 +103,19 @@ define(['./workbox-74d02f44'], (function (workbox) { 'use strict';
 
         return response;
       }
+    }, {
+      handlerDidError: async ({
+        request
+      }) => self.fallback(request)
     }]
   }), 'GET');
   workbox.registerRoute(/.*/i, new workbox.NetworkOnly({
     "cacheName": "dev",
-    plugins: []
+    plugins: [{
+      handlerDidError: async ({
+        request
+      }) => self.fallback(request)
+    }]
   }), 'GET');
 
 }));

File diff suppressed because it is too large
+ 0 - 0
public/sw.js.map


+ 0 - 0
src/pages/editor/index.tsx → src/pages/_offline.tsx


Some files were not shown because too many files changed in this diff