Browse Source

Add a base service worker to cache the audio and font files

pull/1021/head
Timothée Jaussoin 4 years ago
parent
commit
03442bb4ca
  1. 9
      public/scripts/movim_base.js
  2. 48
      public/scripts/movim_sw.js

9
public/scripts/movim_base.js

@ -54,3 +54,12 @@ window.addEventListener('mouseover', onFocusedFunction);
window.addEventListener('focus', onFocusedFunction);
window.addEventListener('blur', function() { isFocused = false; });
window.addEventListener('touchstart', function() { isTouch = true; }, { once: true });
/**
* Register a service worker for the Progressive Web App
*/
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/scripts/movim_sw.js')
.then(() => { console.log('Service Worker Registered'); });
}

48
public/scripts/movim_sw.js

@ -0,0 +1,48 @@
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open('movim').then((cache) => cache.addAll([
// Audio
'/theme/audio/call.ogg',
'/theme/audio/message.ogg',
// Fonts
'/theme/fonts/MaterialIcons/font.css',
'/theme/fonts/MaterialIcons/MaterialIconsRegular.woff2',
'/theme/fonts/Roboto/font.css',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fCRc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fABc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fCBc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fBxc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fCxc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fChc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmSU5fBBc4.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu72xKOzY.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu5mxKOzY.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu7mxKOzY.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu4WxKOzY.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu7WxKOzY.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu7GxKOzY.woff2',
'/theme/fonts/Roboto/KFOmCnqEu92Fr1Mu4mxK.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fCRc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fABc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fCBc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fBxc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fCxc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fChc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmEU9fBBc4.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfCRc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfABc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfCBc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfBxc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfCxc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfChc4EsA.woff2',
'/theme/fonts/Roboto/KFOlCnqEu92Fr1MmWUlfBBc4.woff2',
])),
);
});
self.addEventListener('fetch', (e) => {
e.respondWith(
caches.match(e.request).then((response) => response || fetch(e.request)),
);
});
Loading…
Cancel
Save