-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add service-worder and fixed few issues
- Loading branch information
1 parent
562e86e
commit e964bb6
Showing
15 changed files
with
107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import params from '@params' | ||
|
||
if (params.environment === 'production') { | ||
document.addEventListener('DOMContentLoaded', () => { | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.register('/service-worker.js') | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,12 @@ | |
{{ $bootstrap := resources.GetRemote "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" }} | ||
{{ $libJS := slice $jquery $bootstrap | resources.Concat "script/libraries.js" | resources.Minify | resources.Fingerprint }} | ||
<script src="{{ $libJS.Permalink }}"></script> | ||
{{ $script := resources.Get "script/script.js" | resources.Minify | resources.Fingerprint }} | ||
|
||
{{ $script := resources.Get "script/script.js" }} | ||
{{- $opts := dict | ||
"params" (dict "environment" hugo.Environment) | ||
"minify" true | ||
"fingerprint" true | ||
-}} | ||
{{- $script = $script | js.Build $opts -}} | ||
<script src="{{ $script.Permalink }}"></script> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Set cache version | ||
const version = '1.0.0' | ||
const cacheName = `precache-${version}` | ||
const currentCaches = [cacheName, 'runtime'] | ||
|
||
self.addEventListener('install', (event) => { | ||
event.waitUntil( | ||
caches | ||
.open(cacheName) | ||
.then((cache) => { | ||
return cache.addAll(['./', './index.html']) | ||
}) | ||
.then(self.skipWaiting()), | ||
) | ||
}) | ||
|
||
self.addEventListener('activate', (event) => { | ||
event.waitUntil( | ||
caches | ||
.keys() | ||
.then((keys) => { | ||
return Promise.all( | ||
keys | ||
.filter((key) => !currentCaches.includes(cacheName)) | ||
.map((key) => caches.delete(key)), | ||
) | ||
}) | ||
.then(() => self.clients.claim()), | ||
) | ||
}) | ||
|
||
self.addEventListener('fetch', (event) => { | ||
console.log(event.request.url) | ||
if (event.request.url.startsWith(self.location.origin)) { | ||
event.respondWith( | ||
caches.match(event.request).then((cachedResponse) => { | ||
if (cachedResponse) { | ||
return cachedResponse | ||
} | ||
return caches.open('runtime').then((cache) => { | ||
return fetch(event.request) | ||
.then((response) => { | ||
return cache.put(event.request, response.clone()).then(() => { | ||
return response | ||
}) | ||
}) | ||
.catch(() => { | ||
return caches.open(cacheName).then((cache) => { | ||
return cache.match('/offline/') | ||
}) | ||
}) | ||
.catch(() => { | ||
return new Response('Network error', { | ||
status: 408, | ||
headers: { 'Content-Type': 'text/plain' }, | ||
}) | ||
}) | ||
}) | ||
}), | ||
) | ||
} | ||
}) |