From 5ddba29511313b0e4004a7a45a0e081bdde807a6 Mon Sep 17 00:00:00 2001 From: Rishabh Rawat Date: Tue, 20 Aug 2019 20:27:45 +0530 Subject: [PATCH] pwa work (#239) --- examples/embed.html | 1 + images/icons/icon-144.png | Bin 0 -> 5341 bytes index.html | 14 +++++++++-- manifest.json | 20 +++++++++++++++ offline.html | 12 +++++++++ src/scripts/pwainit.js | 9 +++++++ sw.js | 51 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 images/icons/icon-144.png create mode 100644 manifest.json create mode 100644 offline.html create mode 100644 src/scripts/pwainit.js create mode 100644 sw.js diff --git a/examples/embed.html b/examples/embed.html index de46bc00..c21f46c6 100644 --- a/examples/embed.html +++ b/examples/embed.html @@ -13,6 +13,7 @@ + diff --git a/images/icons/icon-144.png b/images/icons/icon-144.png new file mode 100644 index 0000000000000000000000000000000000000000..6ab78a45a3cc6acc5148e4bb4259956b4898c782 GIT binary patch literal 5341 zcmZ`-XEfYjwEazCFnWy^!ytOE6Jm5BL^o=b5kmA9eRL9GL`g(1A%YMk(ZZ-15j9G5 z(M6Pq7D1l>r?=jRckepqth?{t=bjH|t-IDqGBnVpqF|!{0D$VYj)w77#Q$exq*s1J zYq{wvKwVVzRRQ2#D*W7m%@80DwvOKLafUeEEC@!u)URYr<9_v~WIQNVz~9 z05Fu_)=)KlG_#Wznqf8({z+wHuK9Pg!y`BuB=K`%d;%sbvA9?--5DzT?1l5B@mFZ; z!yLA+W%_KhWjk(PdG+sj*cvhX)vWo<{=S1Sqh-puPj? z+aBINf)`qJgy6afc1yPQEc@&id#V?TL+UiW^W((T9^0teS4BQiK7>DnSA6ey<`m?au%q zNT~({i~E|0$rT5)7@y_xKU~A<6M|@;jFa?}3cdqa_rJg{p-tC8g5*Cy`H*(dIomV1 z5f5l=e;iZ*z2vYo;xpO`z`d&V^! z<)bptq8k5z=iCv6&h>rXeLifAlq4-57y-%m!$m^hCbb%HZ!s;2+27=a6!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CAs{d{+sQ*$ZwdIYf8q zWtr(;L*sp{_Fesj$q~4Rwt1o62N^xGLJmN)U0>d4%`@{Io>GoaiW1Jc2Cs~bdY(|< zN%}#qS^ae{x#r!Y_E!nB#Dc;Ipa2AB0GX%Ri&*NiK2*9QJDWFT;8 z#jRXz+qYxuD#1q+Wgjp7TTroae412`Uw$ry?awjhZ<{C7zKKtzZ(^{`)E8>Vn}wXS z9~@4+{NANn!BO%u!{mfq_sitNdX87b@u>h#R+Y1qk-m2M0{|~>crLO=0 literal 0 HcmV?d00001 diff --git a/index.html b/index.html index 6b458db5..83b01401 100644 --- a/index.html +++ b/index.html @@ -6,11 +6,21 @@ + + + + + + + + Community toolbox - + + + @@ -33,7 +43,7 @@ - + Fork me on GitHub diff --git a/manifest.json b/manifest.json new file mode 100644 index 00000000..eb76c622 --- /dev/null +++ b/manifest.json @@ -0,0 +1,20 @@ +{ + "name": "Community Toolbox", + "short_name": "Community Toolbox", + "start_url": "/index.html", + "scope": ".", + "display": "standalone", + "background_color": "#fff", + "theme_color": "#3F51B5", + "description": "A platform for community growth.", + "dir": "ltr", + "lang": "en-US", + "orientation": "portrait-primary", + "icons": [ + { + "src": "./images/icons/icon-144.png", + "type": "image/png", + "sizes": "144x144" + } + ] +} \ No newline at end of file diff --git a/offline.html b/offline.html new file mode 100644 index 00000000..84207f7b --- /dev/null +++ b/offline.html @@ -0,0 +1,12 @@ + + + + + + + Community Toolbox + + +

Sorry, You're offline!!!

+ + \ No newline at end of file diff --git a/src/scripts/pwainit.js b/src/scripts/pwainit.js new file mode 100644 index 00000000..8d654075 --- /dev/null +++ b/src/scripts/pwainit.js @@ -0,0 +1,9 @@ +var deferredPrompt; + +if('serviceWorker' in navigator) { + navigator.serviceWorker + .register('../../sw.js') + .then(() => { + console.log("Service Worker registered!"); + }) +} diff --git a/sw.js b/sw.js new file mode 100644 index 00000000..2e3d6043 --- /dev/null +++ b/sw.js @@ -0,0 +1,51 @@ +var STATIC_CACHE = "static-v1"; +var DYNAMIC_CACHE = "dynamic-v1"; + +self.addEventListener('install', (e) => { + console.log("[Service Worker] installing..."); +}); + +self.addEventListener('activate', (e) => { + console.log("[Service Worker] activating...",e); + e.waitUntil( + caches.keys() + .then((keyList) => { + return Promise.all(keyList.map((key) => { + if(key !== STATIC_CACHE && key !== DYNAMIC_CACHE) { + return caches.delete(key); + } + })) + }) + ); + + return self.clients.claim(); +}); + + +self.addEventListener('fetch', function (e) { + let urlReq = e.request; + + e.respondWith( + fetch(urlReq) + .then((res) => { + var resClone = res.clone(); + return caches.open(DYNAMIC_CACHE) + .then((cache) => { + cache.delete(urlReq.url) + .then((bool) => { + cache.add(urlReq.url, resClone); + }) + + return res; + }) + }) + .catch((err) => { + return caches.match(urlReq.url) + .then((data) => { + if(data!=undefined) { + return data; + } + }) + }) + ); +}); \ No newline at end of file