aboutsummaryrefslogtreecommitdiffhomepage
path: root/sw.js
diff options
context:
space:
mode:
authorMr.doob <[email protected]>2019-11-18 14:05:35 -0600
committerMr.doob <[email protected]>2019-11-18 14:05:35 -0600
commite0812dbcb8ec24990a0a8fc64de11f711343be74 (patch)
tree86d3ef07e7dc68cc992746bbe5402d8708e1281a /sw.js
parentbc3b88571dcf8935f95a8a17132b63469685549c (diff)
downloadOrca-e0812dbcb8ec24990a0a8fc64de11f711343be74.tar.gz
Orca-e0812dbcb8ec24990a0a8fc64de11f711343be74.zip
Implemented ServiceWorker
Diffstat (limited to 'sw.js')
-rw-r--r--sw.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/sw.js b/sw.js
new file mode 100644
index 0000000..240225c
--- /dev/null
+++ b/sw.js
@@ -0,0 +1,73 @@
+// 220
+
+const assets = [
+
+ './',
+
+ './manifest.json',
+ './desktop/icon.png',
+
+ './desktop/sources/links/style.css',
+ './desktop/sources/links/reset.css',
+ './desktop/sources/links/fonts.css',
+ './desktop/sources/links/main.css',
+ './desktop/sources/links/theme.css',
+
+ './desktop/sources/scripts/lib/acels.js',
+ './desktop/sources/scripts/lib/theme.js',
+ './desktop/sources/scripts/lib/history.js',
+ './desktop/sources/scripts/lib/source.js',
+ './desktop/sources/scripts/core/library.js',
+ './desktop/sources/scripts/core/io.js',
+ './desktop/sources/scripts/core/operator.js',
+ './desktop/sources/scripts/core/orca.js',
+ './desktop/sources/scripts/core/transpose.js',
+ './desktop/sources/scripts/core/io/cc.js',
+ './desktop/sources/scripts/core/io/midi.js',
+ './desktop/sources/scripts/core/io/mono.js',
+ './desktop/sources/scripts/core/io/osc.js',
+ './desktop/sources/scripts/core/io/udp.js',
+ './desktop/sources/scripts/clock.js',
+ './desktop/sources/scripts/commander.js',
+ './desktop/sources/scripts/cursor.js',
+ './desktop/sources/scripts/client.js'
+
+];
+
+self.addEventListener( 'install', async function () {
+
+ const cache = await caches.open( 'Orca' );
+
+ assets.forEach( function ( asset ) {
+
+ cache.add( asset ).catch( function () {
+
+ console.error( '[SW] Cound\'t cache:', asset );
+
+ } );
+
+ } );
+
+} );
+
+self.addEventListener( 'fetch', async function ( event ) {
+
+ const request = event.request;
+ event.respondWith( cacheFirst( request ) );
+
+} );
+
+async function cacheFirst( request ) {
+
+ const cachedResponse = await caches.match( request );
+
+ if ( cachedResponse === undefined ) {
+
+ console.error( '[SW] Not cached:', request.url );
+ return fetch( request );
+
+ }
+
+ return cachedResponse;
+
+}