Update dependency workbox-webpack-plugin to v6 #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^3.4.1
->^6.0.0
By merging this PR, the issue #16 will be automatically resolved and closed:
Release Notes
googlechrome/workbox (workbox-webpack-plugin)
v6.0.0
: Workbox v6.0.0Compare Source
Overview of Workbox v6
We're happy to announce the release of Workbox v6!
🎉 What's New?
webpack improvements
This release includes additional bug fixes for better compatibility with
webpack
. As of this release,workbox-webpack-plugin
requireswebpack
v4.40.0 or later (for those still on the v4.x branch) orwebpack
v.5.9.0 or later (for those who have updated towebpack
v5.x).workbox-webpack-plugin
will also now take advantage of theimmutable
metadata thatwebpack
automatically adds to hashed assets. In most cases, this means that explicitly usingdontCacheBustURLMatching
in yourworkbox-webpack-plugin
configuration is no longer necessary.See #2651, #2673, and #2675.
workbox-strategies improvements
The best way to ensure third-party developers have the power to extend Workbox in ways that fully meet their needs is to base our own strategies on top of the extensibility mechanisms we expose to third-party developers.
Specifically, v6 introduces a new way for third-party developers to define their own Workbox strategies, and all of our built-in strategies have been rewritten on top of this mechanism.
This change also allowed us to rewrite the
workbox-precaching
codebase to useworkbox-strategies
as a base. This should not result in any breaking changes, and should lead to better long-term consistency in how the two modules access the network and cache.See #2446, #2459 and #2569 for more details.
New strategy base class
In v6, all Workbox strategy classes (both built-in strategies as well as custom, third-party strategies) must extend the new
Strategy
base class.The
Strategy
base class is responsible for two primary things:A new "handler" class
We previously had internal modules call
fetchWrapper
andcacheWrapper
, which (as their name implies) wrap the various fetch and cache APIs with hooks into their lifecycle. This is the mechanism that currently allows plugins to work, but it's not exposed to developers.The new "handler" class (which this proposal calls
StrategyHandler
) will expose these methods so custom strategies can callfetch()
orcacheMatch()
and have any plugins that were added to the strategy instance automatically invoked.This class would also make it possible for developers to add their own custom, lifecycle callbacks that might be specific to their strategies, and they would "just work" with the existing plugin interface.
New plugin lifecycle state
In Workbox v5, plugins are stateless. That means if a request for
/index.html
triggers both therequestWillFetch
andcachedResponseWillBeUsed
callbacks, those two callbacks have no way of communicating with each other or even knowing that they were triggered by the same request.In this proposal, all plugin callbacks will also be passed a new
state
object. This state object will be unique to this particular plugin object and this particular strategy invocation (i.e. the call tohandle()
).This allows developers to write plugins where one callback can conditionally do something based on what another callback in the same plugin did (e.g. compute the time delta between running
requestWillFetch
andfetchDidSucceed
orfetchDidFail
).New plugin lifecycle callbacks
In order to fully leverage the plugin lifecycle state (mentioned above), you need to know when the lifecycle of a given strategy invocation starts and finishes.
To address this need (and others), the following new plugin lifecycle callbacks will be added:
handle()
method returns a response. This callback can be used to modify that response before returning it to a route handler or other custom logic.handle()
method returns a response. This callback can be used to record any final response details, e.g. after changes made by other plugins.Developers implementing their own custom strategies do not have to worry about invoking these callbacks themselves; that's all handled by a new
Strategy
base class.More accurate TypeScript types for handlers
TypeScript definitions for various callback methods have been normalized. This should lead to a better experience for developers who use TypeScript and write their own code to implement or call handlers.
See #2548.
workbox-recipes
This release includes a new module,
workbox-recipes
, that combines common routing and caching strategy configurations into ready-to-use code that can be dropped in to your service worker.You can read more about what's included in the first batch of recipes, as well as how to use them, in #2664.
workbox-window improvements
New messageSkipWaiting() method
A new method,
messageSkipWaiting()
, has been added to theworkbox-window
module to simplify the process of telling the "waiting" service worker to activate.This offers some improvements over alternatives:
It calls
postMessage()
with the de facto standard message body,{type: 'SKIP_WAITING'}
, that a service worker generated by Workbox checks for to triggerskipWaiting()
.It chooses the correct "waiting" service worker to post this message to, even if it's not the same service worker that
workbox-window
was registered with.See #2394.
Removal of "external" events in favor of an isExternal property
Many developers were confused by the concept of "external" events in
workbox-window
, and in practice, they did not end up being a net-positive.All "external" events are now represented as "normal" events with an
isExternal
property set totrue
. This allows developers who care about the distinction to still detect it, and developers who don't need to know can ignore the property.See #2031.
Cleaner "Offer a page reload for users" recipe
Taken together, these two changes make the "Offer a page reload for users" recipe cleaner:
sameOrigin parameter in matchCallback functions
A new boolean parameter,
sameOrigin
, is passed to thematchCallback
function used inworkbox-routing.
It's set totrue
if the request is for a same-origin URL, andfalse
otherwise.This simplifies some common boilerplate:
See #2487.
matchOptions are supported in workbox-expiration
You can now set
matchOptions
inworkbox-expiration
, which will then be passed through as theCacheQueryOptions
to the underlyingcache.delete()
call. (Most developers won't need to do this.)See #2206.
Precaching now processes entries one by one, not in bulk
workbox-precaching
has been updated so that only one entry in the precache manifest is requested and cached at a time, instead of attempting to request and cache all of them at once (leaving it to the browser to figure out how to throttle).This should reduce the likelihood of
net::ERR_INSUFFICIENT_RESOURCES
errors while precaching, and also should reduce the bandwidth contention between precaching and simultaneous requests made by the web app.See #2528.
PrecacheFallbackPlugin allows for easier offline fallback
workbox-precaching
now includes aPrecacheFallbackPlugin
, which implements the newhandlerDidError
lifecycle method added in v6.This makes it easy to specify a precached URL as a "fallback" for a given strategy when a response otherwise wouldn't be available. The plugin will take care of properly constructing the correct cache key for the precached URL, including any revision parameter that's needed.
Here's a sample of using it to respond with a precached
/offline.html
when theNetworkOnly
strategy can't generate a response for a navigation request—in other words, displaying a custom offline HTML page:precacheFallback in runtime caching
If you're using
generateSW
to create a service worker for you instead of writing your service worker by hand, you can use the newprecacheFallback
configuration option inruntimeCaching
to accomplish the same thing: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 (likeRoute
s,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, whenPrecacheController
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
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 aPOST
orPUT
request into a cacheableGET
request.You can now use the
cacheKeyWillBeUsed
lifecycle callback in a plugin to return aGET
request with whatever URL you'd like to use as a cache key, and that can then allow the response associated with aPOST
orPUT
to be cached.See #2615 for more details. Thanks to @markbrocato for their contribution.
Build Tools
The minimum required version of node has been increased to
v10.0.0
. This applies toworkbox-build
,workbox-cli
, andworkbox-webpack-plugin
. [#2462]mode
was not intended to be a supported parameter for theinjectManifest
andgetManifest
modes ofworkbox-build
andworkbox-cli
. It's been removed from the documentation and attempting to use it outside ofgenerateSW
will now trigger a build error. This does not apply toworkbox-webpack-plugin
, which does supportmode
in itsInjectManifest
plugin. [#2464]workbox-core
skipWaiting()
method inworkbox-core
wrapped the underlying call toself.skipWaiting()
in aninstall
handler. In practice, this caused undue confusion and offered little value, as it's valid to callself.skipWaiting()
outside of aninstall
event. As of v6, Workbox'sskipWaiting()
will no longer add in aninstall
handler, and is equivalent to just callingself.skipWaiting()
. Because of this, developers should migrate to callingself.skipWaiting()
directly, and Workbox'sskipWaiting()
will likely be removed in v7. [#2547]workbox-precaching
While this scenario is uncommon, if you precache a URL that corresponds to an HTTP redirect to an HTML document on a different origin, that cross-origin HTML document can no longer be used to satisfy a navigation request. [#2484]
By default, the
fbclid
URL query parameter is now ignored when looking up a precached response for a given request. [#2532]Note: The following changes primarily apply to direct usage of the
PrecacheController
class. Most developers don't usePrecacheController
directly, and instead use static helper methods likeprecacheAndRoute()
exported byworkbox-precaching
. [#2639]The
PrecacheController
constructor 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 ofPrecacheController
now take exactly one parameter, which should be set to a correspondingInstallEvent
orActivateEvent
, respectively.The
addRoute()
method has been removed fromPrecacheController
. In its place, the newPrecacheRoute
class 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-precaching
module.) It was removed becausePrecacheRoute
can be used instead.The
createMatchCalback()
method has been removed fromPrecacheController
. The newPrecacheRoute
can be used instead.The
createHandler()
method has been removed fromPrecacheController
. Thestrategy
property of thePrecacheController
object can be used to handle requests instead.The
createHandler()
static export has already been removed from theworkbox-precaching
module. In its place, developers should construct aPrecacheController
instance and use itsstrategy
property.The route registered with
precacheAndRoute()
is now a "real" route that usesworkbox-routing
'sRouter
class 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-routing
setDefaultHandler()
method now takes an optional second parameter corresponding to the HTTP method that it applies to, defaulting to'GET'
. It no longer applies to requests with any HTTP method. If you were usingsetDefaultHandler()
and all of your web app's requests are'GET'
, then no changes need to be made. [#2463]workbox-webpack-plugin
v4.40.0
(for users remaining on the webpackv4.x
major release) orv5.9.0
(for users who have updated to the webpackv5.x
major release). [#2641]v5.1.4
: Workbox v5.1.4Compare Source
The v5.1.4 release contains a dependency update for
rollup-plugin-terser
, resolving a security error with one of its dependencies.See https://github.com/GoogleChrome/workbox/issues/2601
v5.1.3
: Workbox v5.1.3Compare Source
🐛 What's Fixed?
workbox-build
workbox-build
'sgetManifest()
JSDoc [#2429]workbox-cli
swSrc
for hardcoded injection point inwizard
flow [#2451]workbox-core
handlerCallback
JSDocs update [#2440]workbox-precaching
isSWEnv
assertion [#2453]is
[#2466]Thanks!
Special thanks to @akonchady for contributing a PR that went in to this release.
v5.1.2
: Workbox v5.1.2Compare Source
🐛 What's Fixed?
workbox-build
strip-comments
dependency to an earlier revision, to provide continued compatibility with the v8.x.y releases ofnode
. [#2416]Thanks!
Special thanks to @Mister-Hope for raising issues that were resolved in this release.
v5.1.1
: Workbox v5.1.1Compare Source
(We ran into some issues with the
v5.1.0
release process, sov5.1.1
is a republish of the same code.)🎉 What's New?
workbox-routing
hash
portion is displayed. [#2371]workbox-webpack-plugin
compileSrc
option (defaulting totrue
) has been added. If set tofalse
, thenwebpack
will not run theswSrc
file through a compilation. This can be useful if you want yourswDest
output to be, e.g., a JSON file which contains your precache manifest. [#2412]🐛 What's Fixed?
workbox-webpack-plugin
webpack
modules. [#2397]webpackCompilationPlugins
that customize theswSrc
compilation should now be properly applied. [#2400]Thanks!
Special thanks to @aritsune, @bailnl, @novaknole and @pizzafox for raising issues that were resolved in this release.
v5.1.0
Compare Source
v5.0.0
: Workbox v5.0.0Compare Source
Overview of Workbox v5
We're happy to announce the release of Workbox version 5! This release introduces a lot of new features, as well as some breaking changes.
If you're already using Workbox, the best place to get up to speed is the guide to migrating from v4 to v5.
One example migration, with commentary, can be found in this GitHub commit.
🎉 What's New?
A shift towards local Workbox bundles & away from the CDN
While our immediate plan is to continue publishing copies of the Workbox runtime code to our CDN, in v5, the
generateSW
mode of our build tools will create a local bundle of exactly the Workbox runtime methods you end up using in your service worker. Depending on the value ofinlineWorkboxRuntime
, this bundle will either be imported from a separate file, or inlined directly in your top-level service worker.Under the hood, we use Rollup to create this optimized bundle, optionally minifying it and generating sourcemaps, depending on the configuration.
See #2064 for more details.
If you're using the
workbox-webpack-plugin
'sInjectManifest
mode, the service worker file you specify viaswSrc
will end up being run through awebpack
compilation process, optionally applying any compilation plugins configured via thewebpackPlugins
parameter. This should simplify the development flow described in the Using Bundlers (webpack/Rollup) with Workbox guide.See #1513 for more details.
You can continue using
importScripts('http://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js')
and relying onworkbox-sw
to dynamically pull in the Workbox runtime code that you need in v5, but we expect that using a custom bundle will lead to smaller runtime payloads (as well as work around issues with asynchronous imports), and we encourage developers to consider switching off of the CDN.Changes to the webpack precache manifest
Before v5,
workbox-webpack-plugin
would generate a list of entries to precache based on two distinct sources: the set of assets in awebpack
compilation, along with an optional additional set of files matched viaglob
patterns. Mostwebpack
developers did not use theglob
-related options (since thewebpack
compilation would normally include all the assets that they cared about), but at the same time, some helpful configuration options for manipulating or post-processing the precache manifest only applied to entries created via thoseglob
patterns.In v5, the
glob
-related configuration options are no longer supported. Thewebpack
asset pipeline is the source of all the automatically created manifest entries. (Developers who have files that exist outside of thewebpack
asset pipeline are encouraged to use, e.g.,copy-webpack-plugin
to get those files into thewebpack
compilation.)Beyond that, options for post-processing the precache manifest can now be used to manipulate entries that originate from the
webpack
asset pipeline.manifestTransforms
, in particular, can be used to make arbitrary changes to any aspect of the precache manifest, including adding entries, deleting them, and changing theirrevision
orurl
fields as needed. The currentwebpack
compilation will be passed in to the callback function in case you need information from there to determine how to manipulate entries.Here's an example of using
manifestTransforms
to perform extensive post-processing of a precache manifest:Helpers that implement common manifest transformations, like
maximumFileSizeToCacheInBytes
,dontCacheBustURLsMatching
andmodifyURLPrefix
, are also supported forwebpack
assets.See #1591 and #1854.
Additionally, in v5, the precache manifest is inlined into the top-level service worker file, and not stored in a separate, external JavaScript file.
Simplified injectManifest placeholder replacement
Prior to v5, manifest injection worked by using a regular expression to find the correct location in the source service worker file to replace with the array of manifest entries. This could be brittle, and it was hard to customize, since the replacement step assumed you were using a
RegExp
that had capture groups.This is simplified in v5, and using the
injectManifest
mode just checks for a placeholder variable and performs the equivalent of string replacement to inject the full manifest in its place. This variable isself.__WB_MANIFEST
by default.Your
swSrc
file in v4 might have looked likeprecacheAndRoute([]);
In v5, you should change this to
precacheAndRoute(self.__WB_MANIFEST);
self.__WB_MANIFEST
was chosen as the default replacement because self should always be defined in the service worker global scope, and it is unlikely to conflict with any user-created variables. If you need a different replacement, it can be configured via theinjectionPoint
option.See #2059 for more details.
TypeScript support
All browser-based Workbox packages are now written in TypeScript and type definitions have been published to npm. TypeScript users (as well as users with TypeScript-aware code editors) can now get type checking for all browser-exposed Workbox APIs. (There are no TypeScript definitions for the various Workbox build tools at this time.)
To get type definitions for any Workbox APIs, you can import the package as described in our guide on Using Bundlers (webpack/Rollup) with Workbox. For example:
Note, we've historically published our Workbox source modules with the
.mjs
extension as a way to disambiguate them from classic scripts and the examples in our documentation that reference file paths always use.mjs
.However, since TypeScript does not currently support importing .mjs files we publish both
.js
and.mjs
files to npm. TypeScript users wanting to import an individual module should be able to reference it by omitting the extension (which will then default to the.js
file).If you encounter any problems with the type definitions or importing the source files via TypeScript, please let us know by opening an issue on GitHub.
additionalManifestEntries option in build tools
All of the build tools (
generateSW
andinjectManifest
modes inworkbox-build
,workbox-cli
, andworkbox-webpack-plugin
) now support a new option:additionalManifestEntries
. [#2124] It can be set to a list of additional precache manifest entries that go beyond what would normally be included as part of your build (such as CDN URLs), and is a shortcut to something that is otherwise possible via themanifestTransforms
option.Before using this feature, please keep in mind that
workbox-precaching
requires one of two things from each entry in order to keep precached content up to date:revision
field alongside an unversioned URL, providing versioning information that is updated each time new contents are deployed to that URL. E.g.{url: https://example.com/index.js, revision: hashOfIndexJsContents}
The precache manifest entries generated by Workbox's built tools can automatically add in
revision
fields for you, but when usingadditionalManifestEntries
, it's up to you to ensure that you only add in versioned URLs, or that you include arevision
field that will always change whenever the corresponding URL changes.To ensure that developers are aware of this, passing in string values in the
additionalManifestEntries
will result in a non-fatal warning message, asking you to confirm that your URLs are versioned. To avoid this message, pass in an object with arevision: null
property instead of a string, like{url: http://example.com/v1.0.0/index.js, revision: null}
.importScriptsViaChunks in workbox-webpack-plugin's GenerateSW mode
A new option,
importScriptsViaChunks
, is supported in theGenerateSW
mode of the webpack plugin. [#2131] Passing in one or more chunk names will cause the corresponding script files to be included in the generated service worker, viaimportScripts()
.Because of the way script caching works with
importScripts()
, developers should ensure that their chunks' filenames include a hash, so that changes to a chunk's contents will result in new filename.Support for subresource integrity metadata in precaching requests
Precache manifest entries can now include an optional property,
integrity
. If provided, that value will be treated as the integrity metadata for in thefetch()
request used to populate the precache. [#2141]There is currently no option in the Workbox build tools for generating this metadata; it's left as an exercise to developers to use the
manifestTransforms
option to post-process the generated precache manifests and add inintegrity
properties, with appropriate values, to the entries that need that extra validation.update(), to force a service worker update check
A new
update()
method has been added toworkbox-window
. When called, it will invoke theupdate()
method on the underlyingServiceWorkerRegistration
object. [#2136]Calling this method is optional, as browsers will automatically check for service worker updates whenever there's a navigation request to a new page, along with a few other scenarios. However, as described in this guide, manually requesting a service worker update can be useful for long-lived, single-page apps.
Navigation route changes
Two options that were previously supported for navigation routes,
blacklist
andwhitelist
have been renameddenylist
andallowlist
.workbox-routing
previously supported a method,registerNavigationRoute()
, that, under the hood, did two things:fetch
event had amode of 'navigate'
.This is a common pattern to use when implementing the App Shell architecture.
The second step, generating a response by reading from the cache, falls outside of what we see as the responsibilities of
workbox-routing
. Instead, we see it as functionality that should be part ofworkbox-precaching
, via a new method,createHandlerBoundToURL()
. This new method can work hand-in-hand with the existingNavigationRoute
class inworkbox-routing
to accomplish the same logic.If you're using the
navigateFallback
option in one of the build tool's "generate SW" mode, then the switchover will happen automatically. If you previously configured either thenavigateFallbackBlacklist
ornavigateFallbackWhitelist
options, please change those tonavigateFallbackDenylist
ornavigateFallbackAllowlist
, respectively.If you're using "inject manifest" mode or just writing the service worker yourself, and your Workbox v4 service worker calls
registerNavigationRoute()
directly, then you'll have to make a change to your code to get the equivalent behavior.You no longer need to call
getCacheKeyForURL()
, ascreateHandlerBoundToURL()
will take care of that for you.workbox-broadcast-update
A
generatePayload()
configuration option has been added to theBroadcastCacheUpdate
andBroadcastUpdatePlugin
classes that allows developers to customize the message that gets sent to the window when a cached response has been updated.The
generatePayload()
function is called with the same arguments as thecacheDidUpdate()
plugin callback, and its return value will be used as the message payload. Here's an example that adds theLast-Modified
header value of the updated response to the payload:New copyResponse method
A
copyResponse()
method has been added that can be used to clone a response and modify itsheaders
,status
, orstatusText
. [#2193]Here's an example that adds a custom header to indicate that a response came from the cache (and not the network):
Changes to the precaching network requests
If
workbox-precaching
needs to bypass the HTTP cache when requesting a URL, it will now setcache: 'reload'
on the outgoingRequest
, which in turns sets the appropriateCache-Control
headers. [#2176]Previously, bypassing the HTTP cache was done by adding in a
__WB_REVISION=...
URL query parameter to the outgoing network request, meaning that backend web servers would see requests for URLs containing those query parameters. With this change in place, requests for URLs with__WB_REVISION=...
should no longer be seen in HTTP server logs.Please note that this change only applies to outgoing HTTP requests used to populate the precache, and does not apply to cache keys. The keys for some entries created by
workbox-precaching
still include the__WB_REVISION=...
parameter, and it's still a best practice to callgetCacheKeyForURL()
to determine the actual cache key, including the__WB_REVISION
parameter, if you need to access precached entries using the Cache Storage API directly.Control over development logging
A new
__WB_DISABLE_DEV_LOGS
global has been added. Set it tofalse
to disable all logging in development mode. [#2284]New helper methods to read precached responses
Two new methods (
matchPrecache()
andcreateHandler()
) have been added to make it easier to manually access precached assets. [#2254]All build tools
Any
manifestTransform
callbacks are now treated as beingasync
, and each callback will beawait
-ed by the build tools. If you supply multiple transforms, they will still be run sequentially, in the same order. [#2195]This should not be a breaking change, as you can continue providing non-
async
callback functions, and they will still work as before.workbox-build and workbox-cli
As part of a general refactoring of how the options passed to all of our build tools are parsed [#2191], using precaching in the
generateSW
mode ofworkbox-build
andworkbox-cli
is no longer mandatory. You can now use theruntimeCaching
options without configuring theglob
-related options, and your generated service worker will just contain the corresponding runtime caching routes.If you don't configure the
glob
-related options and you don't useruntimeCaching
, that will lead to a build error.All Build Tools
A number of
workbox-build
,workbox-cli
, andworkbox-webpack-plugin
configuration parameters are no longer supported, following the general outlines of the changes described above. For instance,generateSW
will always create a local Workbox runtime bundle for you, so theimportWorkboxFrom
option no longer makes sense. Please consult the relevant tool's documentation for the list of supported options.navigationRouteWhitelist
has been renamednavigationRouteAllowlist
, andnavigationRouteBlacklist
has been renamednavigationRouteDenylist
. The functionality is otherwise identical.All Plugin classes
All
Plugin
classes have been renamed to be package-specific, e.g.ExpirationPlugin
,CacheableResponsePlugin
, etc. If you're using one of the Workbox build tools ingenerateSW
mode to create your service worker, this change will be handled for you automatically. If you use one of the plugins in a manually created service worker, you'll need to explicitly change instances ofPlugin
to the correct revised class name. [#2187]workbox-broadcast-update
The
workbox-broadcast-update
package no longer usesBroadcastChannel
, even in cases when the browser supports it. Instead it usespostMessage()
to message window clients. [#2184]This change was made because
postMessage()
messages are automatically buffered by the window to handle cases where the service worker sends a message before the code running on the window is ready to receive it.BroadcastChannel
has no such buffering, and thus you're more likely to miss message when using it.If you're currently listening for
BroadcastChannel
messages in your code running on the window, you'll now need to listen formessage
events on theServiceWorkerContainer
:Note:
workbox-window
users should not need to make any changes, as its internal logic has been updated to listen forpostMessage()
calls.workbox-build
The
generateSWString
mode has been removed. We expect the impact of this to be minimal, as it was primarily used internally byworkbox-webpack-plugin
.The minimum required version of node has been increased to
v8.0.0
. This also applies to build tools that useworkbox-build
, likeworkbox-cli
andworkbox-webpack-plugin
.workbox-routing
workbox-strategies
makeRequest()
in favor ofhandle()
. CallingmakeRequest()
is mostly equivalent to callinghandle()
on one of theworkbox-strategy
classes. The differences between the two methods were so slight that keeping both around did not make sense. Developers who calledmakeRequest()
should be able to switch to usinghandle()
without any further change. [#2123]workbox-webpack-plugin
webpack
v4 or higher.🐛 What's Fixed?
All build tools
swSrc
file has an associated sourcemap, we now update that to account for the injected manifest. [#2239]workbox-broadcast-update
workbox-precaching
cacheWillUpdate()
plugin callback was not beingawait
-ed. [#2287]workbox-routing
matchCallback
string/number return values through tohandlerCallback
. [#2134]ReadableStream
bug in development mode in Safari. [#2268]workbox-webpack-plugin
workbox-webpack-plugin
in the same compilation, assets created by those other instances will now be excluded from each others' precache manifest. [#2182]workbox-window
isUpdate
property to thecontrolling
event, which was documented but not actually implemented. [#2114]message
event listener is now added earlier, inside of the constructor rather than theregister()
method. [#2211]🙏 Thanks!
A sincere thank you to everyone who tested Workbox v5, and in particular to the following folks who filed bugs and made contributions to the code. (Apologies if we've missed anyone—it's been a long process!)
Code Contributions
Bug Reports
v4.3.1
: Workbox v4.3.1Compare Source
🐛 What's Fixed?
workbox-broadcast-update
workbox-core
, which preventedworkbox-broadcast-update
from notifying on navigation requests. [#2050]v4.3.0
: Workbox v4.3.0Compare Source
🎉 What's New?
workbox-background-sync
getAll()
method to theQueue
class. This can be used to get a list of all unexpired entries in a given queue without removing them. This is useful in situations where replaying the queue is not possible (the user is offline), but you want to show information about the queue to the user. [#2018]🐛 What's Fixed?
Build Tools
workbox
namespace was used before it was defined, whennavigationPreload: true
. [#2007]broadcastUpdate
option inruntimeCaching
. [#2017]workbox-background-sync
Request
wasn't beingclone()
ed before re-adding it to the queue. [#2014]mode
ofsame-origin
. [#2015]Thanks!
Special thanks to @merrywhether and @tarjei for contributions that went into this release.
v4.2.0
: Workbox v4.2.0Compare Source
🎉 What's New?
Build Tools
navigationPreload
config property (defaulting tofalse
) toworkbox-build
'sgenerateSW
andgenerateSWString
modes, which would also expose it to the wrappers likeworkbox-cli
andworkbox-webpack-plugin
. [#1981]workbox-core
Adds
workbox.core.cacheNames.prefix
andworkbox.core.cacheNames.suffix
for accessing the current prefix and suffix used in generating cache names. [#2001]Adds a new
cacheKeyWillBeUsed
lifecycle callback. This allows developers to override the default cache key for reads or writes (or both). [#1990]The interface for the callback looks like:
🐛 What's Fixed?
workbox-webpack-plugin
webpack
loaders [#1966].Thanks!
Special thanks to @merrywhether, @3846masa and @el for contributions that went into this release.
v4.1.1
: Workbox v4.1.1Compare Source
🐛 What's Fixed?
workbox-window
The
removeEventListener()
method of theWorkbox
class would throw due to an implementation error, this has been fixed. [#1963]If, at registration time, there was already both an active and waiting service worker with the same script URL as the one being registered, calling
getSW()
ormessageSW()
after registration would target the active service worker rather than the waiting service worker. The intended behavior is that the target service worker associated with aWorkbox
instance is always the most recently registered service worker with a matching script URL. These methods now target the waiting service worker [#1961]Thanks!
Special thanks to @donavon for contributions that went into this release.
v4.1.0
: Workbox v4.1.0Compare Source
🎉 What's New?
workbox-build
generateSW
option to build your service worker, amessage
listener is now added to the service worker output, which allows you to invokeskipWaiting()
from the window viapostMessage()
[#1929].🐛 What's Fixed?
workbox-window
messageSW()
after an updated service worker is found, it would send the message to the service worker currently controlling the page. This has been fixed [#1941].workbox-precaching
cacheDidUpdate
method were not properly bound, and would fail in some cases. This has been fixed [#1678].workbox-background-sync
If requests were added to a
backgroundSync.Queue
queue due to server error rather than network error, those requests would be retried immediately, which could lead to an infinite loop. This has been fixed [#1943]The
backgroundSync.Queue
class used to storeRequest
bodies asBlob
objects in IndexedDB, but this does not work in Safari. All request bodies are now stored asArrayBuffer
objects [#1932].workbox-broadcast-update
BroadcastCacheUpdate
instance is passed aninstall
event (which happens when using it as a precache plugin) rather than afetch
event, it would error. This has been fixed [#1938].v4.0.0
: Workbox v4.0.0Compare Source
Overview of Workbox v4
We're happy to announce the release of Workbox version 4! This release introduces a lot of great new features, as well as some breaking changes.
You can read the full list of changes here; we've also published a guide on migrating from v3 to v4.
🎉 What's New?
workbox-window
The
workbox-window
package is a set of modules that are intended to run in the window context, which is to say, inside of your web pages. They're a complement to the other workbox packages that run in the service worker.The key features/goals of
workbox-window
are:You can