Skip to content
Gulp plugin to generate a service worker for offlining your app
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

gulp-serviceworker

Generate a Service Worker to make your app work offline.

Build Status dependencies devdependencies

Usage

The plugin has the following options:

  • rootDir: defines the root directory where the resources to be cached are and where the service worker script will be generated.

Example

var gulpServiceWorker = require('gulp-serviceworker');

gulp.task('generate-service-worker', ['build'], function() {
  return gulp.src(['dist/*'])
  .pipe(gulpServiceWorker({
    rootDir: 'dist/',
  }));
});

You also need to register the generated service worker in your pages. Something like:

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('offline-worker.js')
  .then(function(registration) {
    console.log('offline worker registered');
  });
}
You can’t perform that action at this time.