New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW] #30968
Comments
…hness` strategy Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes angular#30968
You are right, @borjapazr. It looks like a bug in the -if (!res.ok || (okToCacheOpaque && res.type === 'opaque')) {
+if (!(res.ok || (okToCacheOpaque && res.type === 'opaque'))) { I have a fix for that in #30977 (see 7352a7f), but we should also add some docs about this (e.g. similar to workbox's). |
@gkalpak that change looks right to me. |
Now it makes sense to me. Thank you @gkalpak. And adding more documentation would be a great idea 😊 |
…hness` strategy Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes angular#30968
…hness` strategy Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes angular#30968
…hness` strategy (#30977) Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes #30968 PR Close #30977
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW]
Relevant Package
This feature request is for @angular/pwa.
Description
The SW might have an option to cache opaque responses in the freshness mode since these caches are short-lived and therefore having an inadequate response would be quickly updated/removed.
I was reading ngsw-worker.js's code and now I have one question.
In the next function, what is the purpose of
okToCacheOpaque
? Is it to avoid having the opaque answers cached or just to the opposite? What is the real usage of this variable now?Could this variable be used to cache opaque responses?
Describe the solution you'd like
Caching opaque responses in the freshness mode of dataGroups in ngsw-config.json
Describe alternatives you've considered
https://medium.com/@sascha.wolff/how-to-use-angular-6-service-worker-for-dynamically-loading-images-f4f6f497699f
The text was updated successfully, but these errors were encountered: