Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

[Deprecated] A collection of service worker tools for offlining runtime requests

License

NotificationsYou must be signed in to change notification settings

GoogleChromeLabs/sw-toolbox

Repository files navigation

sw-toolbox andsw-precache are deprecated in favor of Workbox.Please readthis migration guidefor information on upgrading.

About

A collection of tools forservice workers

Service Worker Toolbox provides some simple helpers for use in creating your own service workers. Specifically, it provides common caching strategies for dynamic content, such as API calls, third-party resources, and large or infrequently used local resources that you don't want precached.

Service Worker Toolbox provides anexpressive approach to using those strategies for runtime requests. If you're not sure what service workers are or what they are for, start withthe explainer doc.

What if I need precaching as well?

Then you should go check outsw-precache before doing anything else. In addition to precaching static resources,sw-precache supports optionalruntime caching through a simple, declarative configuration that incorporates Service Worker Toolbox under the hood.

Install

Service Worker Toolbox is available through Bower, npm or direct from GitHub:

bower install --save sw-toolbox

npm install --save sw-toolbox

git clone https://github.com/GoogleChrome/sw-toolbox.git

Register your service worker

From your registering page, register your service worker in the normal way. For example:

navigator.serviceWorker.register('my-service-worker.js');

As implemented in Chrome 40 or later, 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/. The default scope is the containing path of the service worker script.

For even lower friction, you can instead include the Service Worker Toolbox companion script in your HTML as shown below. Be aware that this is not customizable. If you need to do anything fancier than register with a default scope, you'll need to use the standard registration.

<scriptsrc="/path/to/sw-toolbox/companion.js"data-service-worker="my-service-worker.js"></script>

Add Service Worker Toolbox to your service worker script

In your service worker you just need to useimportScripts to load Service Worker Toolbox:

importScripts('bower_components/sw-toolbox/sw-toolbox.js');// Update path to match your own setup.

Use the toolbox

To understand how to use the toolbox read theUsage andAPI documentation.

License

Copyright 2015-2016 Google, Inc.

Licensed under theApache License, Version 2.0 (the "License");you may not use this file except in compliance with the License. You mayobtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.


[8]ページ先頭

©2009-2025 Movatter.jp