Skip to content

Commit

Permalink
Service worker exploration for offline
Browse files Browse the repository at this point in the history
  • Loading branch information
mk committed Aug 28, 2023
1 parent 0846e10 commit bfcdaaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions public/js/service_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
self.addEventListener('install', event => {
console.log('install', event)
});

self.addEventListener('activate', event => {
console.log('activate', event)
clients.claim();
});

self.addEventListener('fetch', event => {
console.log('fetch', event)
});
5 changes: 4 additions & 1 deletion src/nextjournal/clerk/view.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@
let state = " (-> state v/->edn escape-closing-script-tag pr-str) ".replaceAll('nextjournal.clerk.view/escape-closing-script-tag', 'script')
viewer.init(viewer.read_string(state))\n"
(when conn-ws?
"viewer.connect(document.location.origin.replace(/^http/, 'ws') + '/_ws')")])]))
"if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/js/service_worker.js');
};
viewer.connect(document.location.origin.replace(/^http/, 'ws') + '/_ws')")])]))

0 comments on commit bfcdaaa

Please sign in to comment.