From e61d32f93511833efef972a50a7fd7a9b4eec78d Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Fri, 30 Sep 2016 17:56:23 +0200 Subject: add offline support --- .bowerrc | 3 +++ .gitignore | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- bower.json | 21 ++++++++++++++++++ package.json | 3 ++- public/sw.js | 31 ++++++++++++++++++++++++++ views/index.jade | 10 +++++++++ 6 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 .bowerrc create mode 100644 bower.json create mode 100644 public/sw.js diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000..0b92d57 --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory" : "public/components" +} diff --git a/.gitignore b/.gitignore index f752ff1..6f76b30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ +/public/components -# Created by https://www.gitignore.io/api/node +# Created by https://www.gitignore.io/api/node,bower ### Node ### # Logs @@ -43,3 +44,67 @@ jspm_packages # Optional REPL history .node_repl_history + +# Output of 'npm pack' +*.tgz + + +### Bower ### +bower_components +.bower-cache +.bower-registry +.bower-tmp +# Created by https://www.gitignore.io/api/node,bower + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + + +### Bower ### +bower_components +.bower-cache +.bower-registry +.bower-tmp diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..05be5df --- /dev/null +++ b/bower.json @@ -0,0 +1,21 @@ +{ + "name": "rooster", + "description": "", + "main": "app.js", + "authors": [ + "Noah Loomans " + ], + "license": "MIT", + "homepage": "https://github.com/nloomans/rooster-mml", + "private": true, + "ignore": [ + "**/.*", + "node_modules", + "public/components", + "test", + "tests" + ], + "dependencies": { + "sw-toolbox": "^3.3.0" + } +} diff --git a/package.json b/package.json index 950ddb2..e6b0a58 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "main": "app.js", "private": true, "scripts": { - "start": "node ./bin/www" + "start": "node ./bin/www", + "setup": "npm install && bower install" }, "dependencies": { "bluebird": "^3.4.6", diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..1168c93 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,31 @@ +/* global importScripts toolbox self */ + +// random string: CHfHo0GjMJAoOC + +(global => { + 'use strict' + + // Load the sw-toolbox library. + importScripts('/components/sw-toolbox/sw-toolbox.js') + + // Ensure that our service worker takes control of the page as soon as possible. + global.addEventListener('install', event => event.waitUntil(global.skipWaiting())) + global.addEventListener('activate', event => event.waitUntil(global.clients.claim())) + + toolbox.precache([ + '/', + '/hello', + '/untisinfo.css', + '/javascripts/bundle.js', + '/stylesheets/style.css', + '/stylesheets/hello.css' + ]) + + toolbox.router.get('/', toolbox.cacheFirst) + toolbox.router.get('/hello', toolbox.cacheFirst) + + toolbox.router.get('/javascripts/bundle.js', toolbox.cacheFirst) + toolbox.router.get('/stylesheets/*', toolbox.cacheFirst) + toolbox.router.get('/untisinfo.css', toolbox.cacheFirst) + toolbox.router.get('/meetingpointProxy/*', toolbox.networkFirst) +})(self) diff --git a/views/index.jade b/views/index.jade index b4db649..c219d94 100644 --- a/views/index.jade +++ b/views/index.jade @@ -30,3 +30,13 @@ block content iframe(src='/hello', scrolling='no')#schedule script(src='/javascripts/bundle.js') + script. + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw.js').then(function(registration) { + // Registration was successful + console.log('ServiceWorker registration successful with scope: ', registration.scope) + }).catch(function(err) { + // registration failed :( + console.log('ServiceWorker registration failed: ', err) + }) + } -- cgit v1.1