generate-service-worker
Advanced tools
Comparing version 1.0.0 to 1.2.0
{ | ||
"name": "generate-service-worker", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -19,2 +19,3 @@ Generate Service Worker | ||
cache: { | ||
offline: true, | ||
precache: ['/static/js/bundle-81hj9isadf973adfsh10.js'], | ||
@@ -42,5 +43,6 @@ strategy: [{ | ||
### Caching | ||
The `cache` key is used for defining caching strategies. The strings in `precache` will be used to prefetch assets and insert them into the cache. The regexes in `strategy.matches` are used at runtime to determine which strategy to use for a given GET request. All cached items will be removed at installation of a new service worker version. Additionally, you can use your own custom cache template by including the full path in the `template` property. We suggest forking our `templates/cache.js` file to get started and to be familiar with how variable injection works in the codebase. | ||
The `cache` key is used for defining caching strategies. The strings in `precache` will be used to prefetch assets and insert them into the cache. The regexes in `strategy.matches` are used at runtime to determine which strategy to use for a given GET request. All cached items will be removed at installation of a new service worker version. Additionally, you can use your own custom cache template by including the full path in the `template` property. We suggest forking our `templates/cache.js` file to get started and to be familiar with how variable injection works in the codebase. If the `offline` option is set to `true`, the service worker will assume that an html response is an "App Shell". It will cache the html response and return it only in the case of a static route change while offline. | ||
```js | ||
const CacheType = { | ||
offline?: boolean, | ||
precache?: Array<string>, | ||
@@ -47,0 +49,0 @@ strategy?: Array<StrategyType>, |
@@ -55,2 +55,8 @@ /* eslint-disable no-throw-literal */ | ||
function booleanValidation(value) { | ||
if (!value || typeof value !== 'boolean') { | ||
throw `Value ${value} must be of type "boolean".`; | ||
} | ||
} | ||
function objectValidation(value) { | ||
@@ -89,2 +95,3 @@ if (!value || typeof value !== 'object') { | ||
module.exports = { | ||
boolean: withRequired(booleanValidation), | ||
object: withRequired(objectValidation), | ||
@@ -91,0 +98,0 @@ number: withRequired(numberValidation), |
@@ -9,3 +9,3 @@ const V = require('./validate'); | ||
const CacheShape = V.shape({ | ||
offlineURL: V.string, | ||
offline: V.boolean, | ||
precache: V.arrayOfType(V.string), | ||
@@ -12,0 +12,0 @@ strategy: V.arrayOfType(StrategyShape) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22762
534
96