mirror of
https://github.com/angular/angular.git
synced 2026-11-22 22:55:25 -05:00
docs(service-worker): clarify how applicationMaxAge is measured
The applicationMaxAge docs and schema description read as if the age were counted from when files were cached on the device. The service worker actually compares the age against the manifest timestamp, which is set when ngsw.json is generated at build time. Once the build is older than applicationMaxAge, every request bypasses the cache and goes to the network, even when no newer version has been deployed, so the application does not work offline until a new build is deployed. When the property is omitted, there is no maximum age. Update the guide and the JSON schema description to state this. The format check requires every touched file to be formatted, so this also formats `schema.json`, which was not formatted on main. Fixes #71720
This commit is contained in:
@@ -381,4 +381,8 @@ IMPORTANT: The `freshness` strategy usually results in more requests sent to the
|
||||
|
||||
### `applicationMaxAge`
|
||||
|
||||
This optional property enables you to configure how long the service worker will cache any requests. Within the `maxAge`, files will be served from cache. Beyond it, all requests will only be served from the network, including asset and data requests.
|
||||
This optional property enables you to configure how long the service worker serves an application version from its cache. The age is measured from the time you built the application, not from the time the files were cached on the device.
|
||||
|
||||
Within the `applicationMaxAge`, the service worker serves files from the cache. Beyond it, the service worker sends all requests to the network, including asset and data requests, even if no newer version exists. The application does not work offline until a new build is deployed and the device has fetched it.
|
||||
|
||||
If you omit `applicationMaxAge`, there is no maximum age and the service worker serves cached versions regardless of how old they are.
|
||||
|
||||
@@ -24,18 +24,12 @@
|
||||
"description": "It identifies this particular group of assets between versions of the configuration."
|
||||
},
|
||||
"installMode": {
|
||||
"enum": [
|
||||
"prefetch",
|
||||
"lazy"
|
||||
],
|
||||
"enum": ["prefetch", "lazy"],
|
||||
"default": "prefetch",
|
||||
"description": "Determines how the resources are initially cached. 'prefetch' tells the Angular service worker to fetch every single listed resource while it's caching the current version of the app. This is bandwidth-intensive but ensures resources are available whenever they're requested, even if the browser is currently offline. 'lazy' does not cache any of the resources up front. Instead, the Angular service worker only caches resources for which it receives requests. This is an on-demand caching mode. Resources that are never requested will not be cached. This is useful for things like images at different resolutions, so the service worker only caches the correct assets for the particular screen and orientation."
|
||||
},
|
||||
"updateMode": {
|
||||
"enum": [
|
||||
"prefetch",
|
||||
"lazy"
|
||||
],
|
||||
"enum": ["prefetch", "lazy"],
|
||||
"description": "For resources already in the cache, determines the caching behavior when a new version of the app is discovered. Any resources in the group that have changed since the previous version are updated in accordance with 'updateMode'. 'prefetch' tells the service worker to download and cache the changed resources immediately. 'lazy' tells the service worker to not cache those resources. Instead, it treats them as unrequested and waits until they're requested again before updating them. An 'updateMode' of lazy is only valid if the 'installMode' is also lazy. Defaults to the value `installMode` is set to."
|
||||
},
|
||||
"resources": {
|
||||
@@ -61,10 +55,10 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"cacheQueryOptions" : {
|
||||
"cacheQueryOptions": {
|
||||
"type": "object",
|
||||
"description": "Provide options that are passed to Cache#match.",
|
||||
"properties" : {
|
||||
"properties": {
|
||||
"ignoreSearch": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to ignore the query string in the URL."
|
||||
@@ -73,10 +67,7 @@
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"resources"
|
||||
],
|
||||
"required": ["name", "resources"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
@@ -124,10 +115,7 @@
|
||||
"description": "This duration string specifies the time ahead of the expiration of a cached resource when the Angular service worker should proactively attempt to refresh the resource from the network. The `refreshAhead` duration is an optional configuration that determines how much time before the expiration of a cached response the service worker should initiate a request to refresh the resource from the network."
|
||||
},
|
||||
"strategy": {
|
||||
"enum": [
|
||||
"freshness",
|
||||
"performance"
|
||||
],
|
||||
"enum": ["freshness", "performance"],
|
||||
"default": "performance",
|
||||
"description": "The Angular service worker can use either of two caching strategies for data resources. 'performance', the default, optimizes for responses that are as fast as possible. If a resource exists in the cache, the cached version is used. This allows for some staleness, depending on the 'maxAge', in exchange for better performance. This is suitable for resources that don't change often; for example, user avatar images. 'freshness' optimizes for currency of data, preferentially fetching requested data from the network. Only if the network times out, according to 'timeout', does the request fall back to the cache. This is useful for resources that change frequently; for example, account balances."
|
||||
},
|
||||
@@ -136,16 +124,13 @@
|
||||
"description": "Whether to cache opaque responses or not. The default value is 'false' for groups with the 'performance' strategy and 'true' for groups with the 'freshness' strategy. Opaque responses are special in that it is not possible for the service worker to distinguish successful responses from errors. Therefore, be careful with caching opaque responses, especially when combined with a strategy/configuration that could result in a response being retained in the cache for a long time."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"maxSize",
|
||||
"maxAge"
|
||||
],
|
||||
"required": ["maxSize", "maxAge"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"cacheQueryOptions" : {
|
||||
"cacheQueryOptions": {
|
||||
"type": "object",
|
||||
"description": "Provide options that are passed to Cache#match.",
|
||||
"properties" : {
|
||||
"properties": {
|
||||
"ignoreSearch": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to ignore the query string in the URL."
|
||||
@@ -154,11 +139,7 @@
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"urls",
|
||||
"cacheConfig"
|
||||
],
|
||||
"required": ["name", "urls", "cacheConfig"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
@@ -171,20 +152,15 @@
|
||||
"uniqueItems": true
|
||||
},
|
||||
"navigationRequestStrategy": {
|
||||
"enum": [
|
||||
"freshness",
|
||||
"performance"
|
||||
],
|
||||
"enum": ["freshness", "performance"],
|
||||
"default": "performance",
|
||||
"description": "The Angular service worker can use two request strategies for navigation requests. 'performance', the default, skips navigation requests. The other strategy, 'freshness', forces all navigation requests through the network."
|
||||
},
|
||||
"applicationMaxAge": {
|
||||
"type": "string",
|
||||
"description": "Indicates how long the entire application is allowed to remain in the cache before being considered invalid and bypassed. 'maxAge' is a duration string, using the following unit suffixes: d= days, h= hours, m= minutes, s= seconds, u= milliseconds. For example, the string '3d12h' will cache content for up to three and a half days."
|
||||
"description": "Indicates how long, counted from the time the application was built, the entire application is allowed to be served from the cache before being considered invalid and bypassed. If omitted, there is no maximum age. 'applicationMaxAge' is a duration string, using the following unit suffixes: d= days, h= hours, m= minutes, s= seconds, u= milliseconds. For example, the string '3d12h' will serve cached content for up to three and a half days after the build."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"index"
|
||||
],
|
||||
"required": ["index"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user