Skip to content

xuyizhe/postsw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postsw

Simple post-processing Service Worker.

Installation

npm install -g postsw

Getting started

Register Service Worker

Add the following code to your project.

if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/sw.js');
  });
}

Or use with register-service-worker

Generate sw.js

postsw ./your_project_dist_dir

# postsw --help

Server configuration(optional)

location / {
  index /index.html
  add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
  expires off;
}

location ~ (sw.js)$ {
  add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
  expires off;
}