diff options
author | XhmikosR <xhmikosr@gmail.com> | 2017-07-16 16:54:09 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2017-08-15 14:35:36 +0300 |
commit | 20abbc3c16d39ad92fbf0b497a3690967764a1fd (patch) | |
tree | b165349514270997b095a9922ba4bb240ea1ed59 | |
parent | e9323459ab226d9eb0d15217707c1ce12cf490eb (diff) |
Register a service worker.
-rw-r--r-- | _includes/scripts.html | 1 | ||||
-rw-r--r-- | assets/js/src/pwa.js | 15 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | sw.js | 1 |
4 files changed, 18 insertions, 1 deletions
diff --git a/_includes/scripts.html b/_includes/scripts.html index 058ba1b337..fca6998800 100644 --- a/_includes/scripts.html +++ b/_includes/scripts.html @@ -16,6 +16,7 @@ <script src="{{ site.baseurl }}/assets/js/vendor/clipboard.min.js"></script> <script src="{{ site.baseurl }}/assets/js/vendor/holder.min.js"></script> <script src="{{ site.baseurl }}/assets/js/src/application.js"></script> + <script src="{{ site.baseurl }}/assets/js/src/pwa.js"></script> {% endif %} <script src="{{ site.baseurl }}/assets/js/ie-emulation-modes-warning.js"></script> diff --git a/assets/js/src/pwa.js b/assets/js/src/pwa.js new file mode 100644 index 0000000000..95ee339482 --- /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 0f0618284a..a88d0498b1 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", @@ -0,0 +1 @@ +// empty for now |