workbox-precaching
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "workbox-precaching", | ||
"version": "0.0.2", | ||
"description": "This library is still a work in progress and is not functional.", | ||
"version": "0.0.3", | ||
"description": "A lower-level server worker library to precache a manifest of URLs.", | ||
"keywords": [ | ||
@@ -27,7 +27,7 @@ "workbox", | ||
"devDependencies": { | ||
"workbox-routing": "^0.0.2", | ||
"workbox-runtime-caching": "^0.0.2" | ||
"workbox-routing": "^0.0.3", | ||
"workbox-runtime-caching": "^0.0.3" | ||
}, | ||
"main": "build/importScripts/workbox-precaching.prod.v0.0.2.js", | ||
"module": "build/modules/workbox-precaching.prod.v0.0.2.mjs" | ||
"main": "build/importScripts/workbox-precaching.prod.v0.0.3.js", | ||
"module": "build/modules/workbox-precaching.prod.v0.0.3.mjs" | ||
} |
@@ -1,18 +0,29 @@ | ||
<!-- DO NOT EDIT. This page is autogenerated. --> | ||
<!-- To make changes, edit templates/Project-README.hbs, not this file. --> | ||
# workbox-precaching | ||
This library is still a work in progress and is not functional. | ||
A lower-level server worker library to precache a manifest of URLs. | ||
It's recommended that you use the higher-level [`workbox-sw`](../workbox-sw) | ||
library's `precache()` method rather than using this directly. | ||
## Installation | ||
`npm install --save-dev workbox-precaching` | ||
```sh | ||
npm install --save-dev workbox-precaching | ||
``` | ||
## Demo | ||
## Documentation | ||
Browse sample source code in the [demo directory](https://github.com/GoogleChrome/workbox/tree/master/packages/workbox-precaching/demo). | ||
Read more at this module's [documentation page](https://workboxjs.org/reference-docs/latest/module-workbox-precaching.html). | ||
## Reference Docs | ||
## Sample Code and Examples | ||
You can find [documentation for this module here](https://googlechrome.github.io/workbox/reference-docs/stable/latest/module-workbox-precaching.html#main). | ||
View the | ||
[sample code](https://github.com/GoogleChrome/workbox/tree/master/packages/workbox-precaching/demo) | ||
to see this module put to use. | ||
# What's Workbox? | ||
This module is a part of Workbox, which is a collection of JavaScript libraries | ||
for [Progressive Web Apps](https://developers.google.com/web/progressive-web-apps/). | ||
Visit https://workboxjs.org/ to learn more about what Workbox can do for you. |
@@ -19,10 +19,13 @@ /* | ||
* | ||
* The precaching module provides helpers that make it easy to cache files | ||
* The precaching library intelligently caches and updates files | ||
* during the install step of your service worker. | ||
* | ||
* **Install:** `npm install --save-dev workbox-precaching` | ||
* When given a list of URL's to precache, this module will go through | ||
* each URL and check if the URL is already cached and, if it is, compare | ||
* the hash to see if revision hash has changed. | ||
* | ||
* The revisioned caching will cache bust requests where appropriate and | ||
* only cache assets that have a changed revision asset compared to | ||
* the currently cached value. | ||
* If the revision is old or the entry isn't cached, this library will make | ||
* a request for the asset and cache it, ensuring the the browsers HTTP cache | ||
* is skipped by using `Request.cache = 'reload'` or adding a cache busting | ||
* search parameter to the request. | ||
* | ||
@@ -43,24 +46,12 @@ * @example | ||
* | ||
* const unrevCacheManager = new workbox.precaching.UnrevisionedCacheManager(); | ||
* unrevCacheManager.addToCacheList({ | ||
* unrevisionedFiles: [ | ||
* '/', | ||
* '/images/logo.png' | ||
* ] | ||
* }); | ||
* | ||
* self.addEventListener('install', (event) => { | ||
* const promiseChain = Promise.all([ | ||
* revCacheManager.install(), | ||
* unrevCacheManager.install(), | ||
* ]); | ||
* event.waitUntil(promiseChain); | ||
* event.waitUntil( | ||
* revCacheManager.install() | ||
* ); | ||
* }); | ||
* | ||
* self.addEventListener('activate', (event) => { | ||
* const promiseChain = Promise.all([ | ||
* revCacheManager.cleanup(), | ||
* unrevCacheManager.cleanup() | ||
* ]); | ||
* event.waitUntil(promiseChain); | ||
* event.waitUntil( | ||
* revCacheManager.cleanup() | ||
* ); | ||
* }); | ||
@@ -73,4 +64,2 @@ * | ||
'./lib/controllers/revisioned-cache-manager.js'; | ||
import UnrevisionedCacheManager from | ||
'./lib/controllers/unrevisioned-cache-manager.js'; | ||
@@ -86,3 +75,2 @@ import environment from '../../../lib/environment.js'; | ||
RevisionedCacheManager, | ||
UnrevisionedCacheManager, | ||
}; |
@@ -6,3 +6,3 @@ import ErrorFactory from '../error-factory'; | ||
* assets. | ||
* @private | ||
* | ||
* @memberof module:workbox-precaching | ||
@@ -58,4 +58,4 @@ */ | ||
/** | ||
* Gives access to the cache name used by thie caching manager. | ||
* @return {String} The cache name used for this manager. | ||
* Gives access to the cache name used by this caching manager. | ||
* @return {String} The cache name used by this manager. | ||
*/ | ||
@@ -69,2 +69,3 @@ getCacheName() { | ||
* cache manager. | ||
* | ||
* @return {Array<String>} An array of URLs that will be cached. | ||
@@ -112,7 +113,7 @@ */ | ||
/** | ||
* Manages the service worker install event and caches the revisioned | ||
* assets. | ||
* This method will go through each asset added to the cache list and | ||
* fetch and update the cache for assets which have a new revision hash. | ||
* | ||
* @return {Promise} The promise resolves when all the desired assets are | ||
* cached. | ||
* cached and up -to-date. | ||
*/ | ||
@@ -119,0 +120,0 @@ async install() { |
@@ -13,17 +13,21 @@ import ErrorFactory from '../error-factory'; | ||
/** | ||
* This class extends a lot of the internal methods from BaseCacheManager | ||
* to manage caching of revisioned assets. | ||
* You can instantiate this class to add requests to a precache list and | ||
* eventually install the assets by calling [install()]{@link | ||
* module:workbox-precaching.BaseCacheManager#install} and to remove | ||
* old entries call [cleanup()]{@link | ||
* module:workbox-precaching.RevisionedCacheManager#cleanup}. | ||
* | ||
* @private | ||
* @memberof module:workbox-precaching | ||
* @extends {module:workbox-precaching.BaseCacheManager} | ||
* @extends module:workbox-precaching.BaseCacheManager | ||
*/ | ||
class RevisionedCacheManager extends BaseCacheManager { | ||
/** | ||
* Constructor for RevisionedCacheManager | ||
* Constructs a new RevisionedCacheManager to handle caching of revisioned | ||
* assets only. | ||
* | ||
* @param {Object} input | ||
* @param {String} [input.cacheName] Define the cache used to stash these | ||
* entries. | ||
* @param {String} [input.cacheId] The cacheId can be used to ensure that | ||
* multiple projects sharing `http://localhost` have unique cache names. | ||
* @param {String} [input.cacheName] The cache to be used for precaching. | ||
* @param {String} [input.cacheId] The cacheId is prepended to the | ||
* cache name. This is useful if you have multiple projects sharing | ||
* the same `http://localhost` origin and want unique cache names. | ||
* @param {Array<Object>} [input.plugins] Any plugins that should be | ||
@@ -41,8 +45,23 @@ * invoked by the underlying `RequestWrapper`. | ||
/** | ||
* This method will add the entries to the install list. | ||
* This will manage duplicate entries and perform the caching during | ||
* the install step. | ||
* This method will add the supplied entries to the install list and | ||
* can be called multiple times. | ||
* | ||
* The `revisionedFiles` parameter of the input should contain an array | ||
* of objects or strings. | ||
* | ||
* Objects in this array should have a `url` and `revision` parameter where | ||
* the revision is a hash, unique to the files contents, which changes | ||
* whenever the file is updated. (See our [getting started guide to learn | ||
* how to automate this](/#get-started)). | ||
* | ||
* Strings should be URL's that contain revisioning information | ||
* i.e. `/styles/main.abcd.css` instead of `/styles/main.css`. If you supply | ||
* a URL which *isn't* revisioned, the `install()` step will **never** update | ||
* the precached asset. | ||
* | ||
* @param {Object} input | ||
* @param {Array<String|Object>} input.revisionedFiles This should be an | ||
* array of either objects or strings. | ||
* | ||
* @example | ||
* | ||
* revisionedManager.addToCacheList({ | ||
@@ -57,5 +76,2 @@ * revisionedFiles: [ | ||
* }); | ||
* | ||
* @param {Array<String|Object>} rawEntries A raw entry that can be | ||
* parsed into a BaseCacheEntry. | ||
*/ | ||
@@ -185,6 +201,8 @@ addToCacheList({revisionedFiles} = {}) { | ||
/** | ||
* Compare the URL's and determines which assets are no longer required | ||
* in the cache. | ||
* This method will compare the currently cached requests's and determine | ||
* which requests are no longer in the cache list and can be removed from the | ||
* cache. | ||
* | ||
* This should be called in the service worker activate event. | ||
* This should be called in a service worker's activate event to avoid | ||
* removing requests that are still be used by currently open pages. | ||
* | ||
@@ -191,0 +209,0 @@ * @return {Promise} Promise that resolves once the cache entries have been |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances 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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
30
5
861142
2
80
6599