https://github.com/xuyizhe/postsw
Simple post-processing Service Worker.
https://github.com/xuyizhe/postsw
cli service-worker workbox
Last synced: 12 months ago
JSON representation
Simple post-processing Service Worker.
- Host: GitHub
- URL: https://github.com/xuyizhe/postsw
- Owner: xuyizhe
- License: mit
- Created: 2020-07-14T03:32:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T11:26:02.000Z (over 3 years ago)
- Last Synced: 2025-06-01T13:43:16.179Z (about 1 year ago)
- Topics: cli, service-worker, workbox
- Language: JavaScript
- Homepage:
- Size: 333 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# postsw
Simple post-processing Service Worker.
## Installation
```shell
npm install -g postsw
```
## Getting started
### Register Service Worker
Add the following code to your project.
```javascript
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js');
});
}
```
Or use with [`register-service-worker`](https://www.npmjs.com/package/register-service-worker)
### Generate `sw.js`
```shell
postsw ./your_project_dist_dir
# postsw --help
```
### Server configuration(optional)
```shell
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;
}
```