Skip to content

Commit

Permalink
service worker bugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Steeven Andrian committed Nov 12, 2019
1 parent cdc8788 commit 4ebf880
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "./app.scss";

if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('service-worker.js')
.register('/service-worker.js')
.then(function(registration) {
console.info(
'Service Worker registration successful with scope: ',
Expand Down
25 changes: 16 additions & 9 deletions resources/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@
*/
// ------------------------------------------------------------------------

const APP_NAME = '{{$appName}}';
const THEME_NAME = '{{$themeName}}';
const CACHE_NAME = '{{$cacheName}}';
const APP_NAME = '{{ $appName }}';
const CACHE_NAME = APP_NAME + '_cache';
const THEME_NAME = '{{ $themeName }}';

self.addEventListener('install', function(event) {
console.info('[' + APP_NAME + '] Installing Service Worker ...', event);
event.waitUntil(
caches.open(CACHE_NAME).then(function(cache) {
cache.addAll([
'/themes/' + THEME_NAME + '/theme.css',
'/assets/app.css',
'/themes/' + THEME_NAME + '/theme.js',
'/assets/app.js'
]);
if(THEME_NAME === '') {
cache.addAll([
'/assets/app.css',
'/assets/app.js'
]);
} else {
cache.addAll([
'/themes/' + THEME_NAME + '/theme.css',
'/assets/app.css',
'/themes/' + THEME_NAME + '/theme.js',
'/assets/app.js'
]);
}
})
);
});
Expand Down

0 comments on commit 4ebf880

Please sign in to comment.