From 78ee44662c5b561e6d8539893296981574cb7ef2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 17 Jun 2021 22:42:08 -0600 Subject: [PATCH] Add PWA + ServiceWorker with offline support --- public/offline.html | 61 +++++++++++++++++++++++++++++++++++++ public/sw.js | Bin 0 -> 1091 bytes resources/assets/js/app.js | 8 ++++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 public/offline.html create mode 100644 public/sw.js diff --git a/public/offline.html b/public/offline.html new file mode 100644 index 000000000..b216ae2ea --- /dev/null +++ b/public/offline.html @@ -0,0 +1,61 @@ + + + + + + + + You are offline + + + +
+
+

+ icon/color/svg/pixelfed-icon-color Created with Sketch. +

+

You are offline

+ +

Click the button below to try reloading.

+

+ +

+
+
+ + + + diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000000000000000000000000000000000000..b88112cf2ebc2b025fc255cafaf63dc4fac1a2b5 GIT binary patch literal 1091 zcmbVLU2EGg6n&O|h47OMMPsim8I_xi>9e}V8UGa00tZ@6*d)GmnW1#L@GM_L0<}zKKNd!aAShf ztRRF5|7;{>LkJ<6mlSdh*i*!4n!Y@@TQKaEadn0T$WcV3!VK)`5+0wx2X@5&gudi5 zr?hmSt!PTxRjEW*v8o{PZ_?u*)be{7+~LL9Qn%qkue9 zmks9|+u+n@xGOy&C^PdR%x|q}ZdF*v;lDF|65Mkywcmtowq*%1)xYjUt~f%ISVAJP z5i%G^h=cIt3?1QpW;6<)yo3hA-nxfL>*U5;<=N&#@lj?j-r)kGjp&(k)*T3acHswh g=~6Tka_N|FVyEN%9}#?;-1AGDk}gBK4PDy(e=Lko761SM literal 0 HcmV?d00001 diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 2d1af4b41..8471cd6d4 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -34,6 +34,12 @@ window.App.boot = function() { new Vue({ el: '#content'}); } +window.addEventListener("load", () => { + if ("serviceWorker" in navigator) { + navigator.serviceWorker.register("/sw.js"); + } +}); + window.App.util = { compose: { post: (function() { @@ -230,4 +236,4 @@ window.App.util = { .attr('width', 34).attr('height', 34); }) -}; \ No newline at end of file +};