diff --git a/lib/ember-addon.js b/lib/ember-addon.js index 162893e..c2b03d5 100644 --- a/lib/ember-addon.js +++ b/lib/ember-addon.js @@ -2,6 +2,7 @@ var path = require('path'); var fs = require('fs'); var mergeTrees = require('broccoli-merge-trees'); var funnel = require('broccoli-funnel'); +var stringifile = require('stringifile'); var serviceWorker = require('./service-worker.js'); @@ -48,18 +49,7 @@ module.exports = { contentFor: function(type, config) { if (config.environment !== 'test' && type === 'body-footer') { - var lines = []; - lines.push(''); - return lines.join('\n'); + return stringifile('registration.js', 'script', __dirname); } } }; diff --git a/lib/registration.js b/lib/registration.js new file mode 100644 index 0000000..47023f9 --- /dev/null +++ b/lib/registration.js @@ -0,0 +1,8 @@ +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('./service-worker.js', {scope: './'}) + .catch(function(error) { + alert('Error registering service worker:'+error); + }); +} else { + alert('service worker not supported'); +} \ No newline at end of file diff --git a/package.json b/package.json index d70d0c5..13aaef3 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,8 @@ "broccoli-merge-trees": "~0.1.4", "broccoli-writer": "~0.1.1", "serviceworker-cache-polyfill": "^3.0.0" + }, + "devDependencies": { + "stringifile": "^0.1.1" } }