Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

broccoli-serviceworker

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-serviceworker

A broccoli plugin automating ServiceWorker file creation for Broccoli and Ember.js

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

broccoli-serviceworker

ServiceWorker generator for Broccoli and Ember.js. Derived from broccoli-manifest.

For more details on ServiceWorker check out the following:

Usage for Ember Cli

npm install --save-dev broccoli-serviceworker

//app/config/environment.js

ENV.serviceWorker = {
  enabled: true,
  serviceWorkerFile: "service-worker.js",
  excludePaths: ['tests/', 'online.html',],
  includePaths: ['/'],
  fallback: [
    '/online.html offline.html'      
  ],
  dynamicCache: [
    '/api/todos'
  ]
};

Upgrade your index.html (see below) and you are done. The service worker bootstrap logic will be added to your index.html automatically, using contentFor hooks.

Usage for Broccoli.js

npm install --save broccoli-serviceworker

Use broccoli-serviceworker as your last filter in the Brocfile.js like this

var writeServiceWorker = require('broccoli-serviceworker');

...

var completeTree = mergeTrees([appJs, appCss, publicFiles]);

module.exports = mergeTrees([completeTree, writeServiceWorker((completeTree)]);

Options

You can pass some options as the second argument to writeServiceWorker:


writeServiceWorker(completeTree, {
  serviceWorkerFile: "service-worker.js",
  excludePaths: ['tests/', 'online.html',],
  includePaths: ['/'],
  fallback: [
    '/online.html offline.html'      
  ],
  dynamicCache: [
    '/api/todos'
  ],
  skipWaiting: true
});

Files can be filtered using regular expressions.

{
  excludePaths: ['index.html', new RegExp(/.\.map$/)],
  includePaths: ['']
}

Upgrade your index.html

In order to use the generated serviceworker, you will need to register the serviceworker. This is done automatically if using as an Ember.js addon. If you're not using Ember.js, you can use the following code:

<!DOCTYPE html>
<html>
  ...
  <script>
    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');
    }      
  </script>
</html>

Keywords

FAQs

Package last updated on 23 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc