Browse Source

Determine service worker script path based on path of main script.

master
Dan 1 year ago
parent
commit
cc963ebce3
1 changed files with 3 additions and 1 deletions
  1. 3
    1
      src/index.js

+ 3
- 1
src/index.js View File

@@ -10,7 +10,9 @@ function App() {
10 10
 
11 11
     function create() {
12 12
         if ('serviceWorker' in navigator) {
13
-            navigator.serviceWorker.register('/ipfs/fetcher.js')
13
+            const this_script_url = document.currentScript.src;
14
+            const base_script_url = this_script_url.slice(0, this_script_url.lastIndexOf('/'))
15
+            navigator.serviceWorker.register(base_script_url + '/fetcher.js')
14 16
             .then((registration) => {
15 17
                 console.log('registered the service worker successfully')
16 18
 

Loading…
Cancel
Save