Workbox v6.0.0-alpha.3
Pre-releaseOverview 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 Routes, 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 webpack v4.x.
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 webpack v5.0.0.
Note: At this time, workbox-webpack-plugin has issues detecting the correct URLs for HTML assets created by html-webpack-plugin in webpack v5.0.0. You can follow jantimon/html-webpack-plugin#1522 for updates.
cacheKeyWillBeUsed can be used to cache non-GET requests
Only 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 POST or PUT request into a cacheable GET request.
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 POST or PUT to be cached.
See #2615 for more details. Thanks to @markbrocato for their contribution.
⚠️ Breaking Changes
workbox-precaching
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 workbox-precaching. [#2639]
-
The
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),plugins(replacing theaddPlugins()method from v5), andfallbackToNetwork(replacing the similar option that was passed tocreateHandler()and `createHandlerBoundToURL() in v5). -
The
install()andactivate()methods ofPrecacheControllernow take exactly one parameter, which should be set to a correspondingInstallEventorActivateEvent, respectively. -
The
addRoute()method has been removed fromPrecacheController. In its place, the newPrecacheRouteclass can be used to create a route that you can then register. -
The
precacheAndRoute()method has been removed fromPrecacheController. (It still exists as a static helper method exported by theworkbox-precachingmodule.) It was removed becausePrecacheRoutecan be used instead. -
The
createMatchCalback()method has been removed fromPrecacheController. The newPrecacheRoutecan be used instead. -
The
createHandler()method has been removed fromPrecacheController. Thestrategyproperty of thePrecacheControllerobject can be used to handle requests instead. -
The
createHandler()static export has already been removed from theworkbox-precachingmodule. In its place, developers should construct aPrecacheControllerinstance and use itsstrategyproperty. -
The route registered with
precacheAndRoute()is now a "real" route that usesworkbox-routing'sRouterclass under the hood. This may lead to a different evaluation order of your routes if you interleave calls toregisterRoute()andprecacheAndRoute(). See #1857 and #2402 for more details.
workbox-webpack-plugin
- The minimum required version of webpack has been increased to
v4.4.0. (See previous section for otherwebpackupdates.) [#2641]
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.