From 39f62cc82c833786fc639668dd6669e06778ba4f Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 16 Jul 2017 16:54:09 +0300 Subject: [PATCH] Register a service worker. --- _includes/scripts.html | 1 + assets/js/src/pwa.js | 15 +++++++++++++++ package.json | 2 +- sw.js | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 assets/js/src/pwa.js create mode 100644 sw.js diff --git a/_includes/scripts.html b/_includes/scripts.html index da73fdd68aa0..83cd120089a4 100644 --- a/_includes/scripts.html +++ b/_includes/scripts.html @@ -16,6 +16,7 @@ + {% endif %} diff --git a/assets/js/src/pwa.js b/assets/js/src/pwa.js new file mode 100644 index 000000000000..95ee339482e9 --- /dev/null +++ b/assets/js/src/pwa.js @@ -0,0 +1,15 @@ +/* eslint no-console:off */ + +(function setupSW() { + 'use strict' + + if ('serviceWorker' in navigator) { + window.addEventListener('load', function () { + navigator.serviceWorker.register('/sw.js').then(function (registration) { + console.log('ServiceWorker registration successful with scope: ', registration.scope) + }).catch(function (err) { + console.log('ServiceWorker registration failed: ', err) + }) + }) + } +}()) diff --git a/package.json b/package.json index e4b2180bd1a8..9053a851004d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "js-compile-bundle": "shx cat js/src/util.js js/src/alert.js js/src/button.js js/src/carousel.js js/src/collapse.js js/src/dropdown.js js/src/modal.js js/src/scrollspy.js js/src/tab.js js/src/tooltip.js js/src/popover.js | shx sed \"s/^(import|export).*//\" | babel --filename js/src/bootstrap.js | node build/stamp.js > dist/js/bootstrap.js", "js-compile-plugins": "babel js/src/ --out-dir js/dist/ --source-maps", "js-minify": "uglifyjs --config-file build/uglifyjs.config.json --output dist/js/bootstrap.min.js dist/js/bootstrap.js", - "js-minify-docs": "uglifyjs --config-file build/uglifyjs.config.json --output assets/js/docs.min.js assets/js/vendor/anchor.min.js assets/js/vendor/clipboard.min.js assets/js/vendor/holder.min.js assets/js/src/application.js", + "js-minify-docs": "uglifyjs --config-file build/uglifyjs.config.json --output assets/js/docs.min.js assets/js/vendor/anchor.min.js assets/js/vendor/clipboard.min.js assets/js/vendor/holder.min.js assets/js/src/application.js assets/js/src/pwa.js", "js-test": "phantomjs ./node_modules/qunit-phantomjs-runner/runner.js js/tests/index.html 60", "js-test-cloud": "ruby -r webrick -e \"s = WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd, :Logger => WEBrick::Log.new('/dev/null'), :AccessLog => []); trap('INT') { s.shutdown }; s.start\" & grunt saucelabs-qunit", "docs": "npm-run-all docs-compile docs-lint", diff --git a/sw.js b/sw.js new file mode 100644 index 000000000000..44d1d2774a24 --- /dev/null +++ b/sw.js @@ -0,0 +1 @@ +// empty for now