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

This commit is contained in:
Dan 2017-12-26 21:26:01 -08:00
parent def02e77a7
commit cc963ebce3
1 changed files with 3 additions and 1 deletions

View File

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