Overview of Workbox v6
We're happy to announce the third alpha release of Workbox v6! In addition to the changes outlined in the previous release notes, the following has changed since Workbox v5.
🎉 What's New?
Under-the-hood workbox-precaching improvements
This release includes a substantial rewrite to the implementation of
workbox-precaching, to build on top of other standard Workbox idioms (like
Strategy subclasses, and custom plugins) as much as possible. There are a few breaking changes, described in the follow section, but they are mostly limited to uncommon use cases, when
PrecacheController is instantiated directly. For the most part, these changes are meant to be invisible to developers, but should lead to be better consistency in how routing and request handling works across all of Workbox.
You can read more about what's change in #2638
webpack v5 compatibility
As of this release,
workbox-webpack-plugin should be compatible with
webpack v5.0.0. We have also raised the minimum required version of
webpack to v4.4.0, which should be a straightforward upgrade for developers who need to remain on
While all of the public interfaces remain the same, signfifcant changes were made to the code used to determine which
webpack assets make it into your precache manifest. These take advantage of new methods that were added in
webpack v4.4.0, and which have to be used in
webpack v5.0.0. We encourage developers to test
workbox-webpack-plugin carefully, and raise issues if you find discrepencies like URLs missing from your precache manifest! This applies whether you are remaining on
webpack v4.4.0, or are upgrade to
Note: At this time,
workbox-webpack-plugin has issues detecting the correct URLs for HTML assets created by
webpack v5.0.0. You can follow https://github.com/jantimon/html-webpack-plugin/issues/1522 for updates.
cacheKeyWillBeUsed can be used to cache non-GET requests
GET requests can be used as cache keys, but there are scenarios in which you might want to use a combination of plugins to transform a
PUT request into a cacheable
You can now use the
cacheKeyWillBeUsed lifecycle callback in a plugin to return a
GET request with whatever URL you'd like to use as a cache key, and that can then allow the response associated with a
PUT to be cached.
See #2615 for more details. Thanks to @markbrocato for their contribution.
⚠️ Breaking Changes
Note: The following changes primarily apply to direct usage of the
PrecacheController class. Most developers don't use
PrecacheController directly, and instead use static helper methods like
precacheAndRoute() exported by
PrecacheControllerconstructor now takes in an object with specific properties as its parameter, instead of a string. This object supports the following properties:
cacheName(serving the same purpose as the string that was passed in to the constructor in v5),
addPlugins()method from v5), and
fallbackToNetwork(replacing the similar option that was passed to
createHandler()and `createHandlerBoundToURL() in v5).
PrecacheControllernow take exactly one parameter, which should be set to a corresponding
addRoute()method has been removed from
PrecacheController. In its place, the new
PrecacheRouteclass can be used to create a route that you can then register.
precacheAndRoute()method has been removed from
PrecacheController. (It still exists as a static helper method exported by the
workbox-precachingmodule.) It was removed because
PrecacheRoutecan be used instead.
createMatchCalback()method has been removed from
PrecacheController. The new
PrecacheRoutecan be used instead.
createHandler()method has been removed from
strategyproperty of the
PrecacheControllerobject can be used to handle requests instead.
createHandler()static export has already been removed from the
workbox-precachingmodule. In its place, developers should construct a
PrecacheControllerinstance and use its
The route registered with
precacheAndRoute()is now a "real" route that uses
Routerclass under the hood. This may lead to a different evaluation order of your routes if you interleave calls to
precacheAndRoute(). See #1857 and #2402 for more details.
- The minimum required version of webpack has been increased to
v4.4.0. (See previous section for other
Installation of the latest pre-release version
We are using the
next tag in
npm for the current pre-release version. To install a given module use, e.g.,
npm install --save-dev workbox-webpack-plugin@next.