forked from GoogleChromeLabs/sw-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
930 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"forin": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"plusplus": false, | ||
"quotmark": "single", | ||
"undef": true, | ||
"unused": "vars", | ||
"strict": true, | ||
|
||
"worker": true, | ||
"devel": true, | ||
"node": true, | ||
"predef": ["fetch", "Request", "Response", "caches", "self", "URL"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Shed | ||
|
||
A collection of tools for Workers | ||
|
||
## Service Worker helpers | ||
|
||
Shed provides some simple helpers for use in creating your own service workers. If you're not sure what service workers are or what they are for, start with [the explainer doc](https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md). | ||
|
||
From your registering page, register your service worker in the normal way: | ||
|
||
```javascript | ||
navigator.serviceWorker.register('/service-worker.js', {scope: '/'}); | ||
``` | ||
|
||
As currently implemented in Chrome 40, a service worker must exist at the root of the scope that you intend it to control, or higher. So if you want all of the pages under `/myapp/` to be controlled by the worker, the worker script itself must be served from either `/` or `/myapp/`. | ||
|
||
In your service worker you just need to use `importScripts` to load Shed | ||
|
||
```javascript | ||
importScripts('../shed/dist/shed.js'); | ||
``` | ||
|
||
## API | ||
|
||
```javascript | ||
// shed.router has get, put, post, delete, head and any methods, matching HTTP | ||
// verbs. It uses ExpressJS style route syntax, extended to allow absolute URLs | ||
// on other domains | ||
shed.router.get('http://example.com/:page', function(request, keys) { | ||
return new Response('Handled a request for http://example.com/' + keys.page); | ||
}); | ||
|
||
// The built-in handlers are networkFirst, networkOnly, cacheFirst, cacheOnly | ||
// and fastest | ||
shed.router.get('/shed-demo/:foo/:bar', shed.networkOnly); | ||
|
||
// You can use relative URLs, which are relative to the scope of the worker | ||
shed.router.get(':foo/:bar', shed.networkOnly); | ||
|
||
// At the moment, if the fetch is for a URL that doesn't match a route, you get | ||
// some default behaviour. The 'default default' is netowrkOnly, but you can | ||
// change it like so: | ||
shed.router.default = shed.cacheFirst; | ||
|
||
// If you want some resources to be cached during the install event, specify | ||
// them with the precache method | ||
shed.precache(['/index.html', '/site.css', '/images/logo.png']); | ||
|
||
// You can manually add or remove things from the cache | ||
shed.cache('/data/2014/posts.json'); | ||
shed.uncache('/data/2013/posts.json'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
self.shed = require('../lib/shed.js'); |
Oops, something went wrong.