Title: Support caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW] · Issue #30968 · angular/angular · GitHub
Open Graph Title: Support caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW] · Issue #30968 · angular/angular
X Title: Support caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW] · Issue #30968 · angular/angular
Description: 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...
Open Graph Description: 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 res...
X Description: 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 res...
Opengraph URL: https://github.com/angular/angular/issues/30968
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW]","articleBody":"# Caching opaque responses with freshness strategy in ngsw-config.json [PWA][SW]\r\n\r\n### Relevant Package\r\nThis feature request is for @angular/pwa.\r\n\r\n\r\n### Description\r\nThe 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.\r\n\r\nI was reading ngsw-worker.js's code and now I have one question.\r\nIn 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?\r\nCould this variable be used to cache opaque responses?\r\n\r\n```javascript\r\n/**\r\n * Operation for caching the response from the server. This has to happen all\r\n * at once, so that the cache and LRU tracking remain in sync. If the network request\r\n * completes before the timeout, this logic will be run inline with the response flow.\r\n * If the request times out on the server, an error will be returned but the real network\r\n * request will still be running in the background, to be cached when it completes.\r\n */\r\n cacheResponse(req, res, lru, okToCacheOpaque = false) {\r\n return __awaiter$1(this, void 0, void 0, function* () {\r\n // Only cache successful responses.\r\n if (!res.ok || (okToCacheOpaque \u0026\u0026 res.type === 'opaque')) {\r\n return;\r\n }\r\n // If caching this response would make the cache exceed its maximum size, evict something\r\n // first.\r\n if (lru.size \u003e= this.config.maxSize) {\r\n // The cache is too big, evict something.\r\n const evictedUrl = lru.pop();\r\n if (evictedUrl !== null) {\r\n yield this.clearCacheForUrl(evictedUrl);\r\n }\r\n }\r\n // TODO: evaluate for possible race conditions during flaky network periods.\r\n // Mark this resource as having been accessed recently. This ensures it won't be evicted\r\n // until enough other resources are requested that it falls off the end of the LRU chain.\r\n lru.accessed(req.url);\r\n // Store the response in the cache (cloning because the browser will consume\r\n // the body during the caching operation).\r\n yield (yield this.cache).put(req, res.clone());\r\n // Store the age of the cache.\r\n const ageTable = yield this.ageTable;\r\n yield ageTable.write(req.url, { age: this.adapter.time });\r\n // Sync the LRU chain to non-volatile storage.\r\n yield this.syncLru();\r\n });\r\n }\r\n```\r\n\r\n### Describe the solution you'd like\r\nCaching opaque responses in the freshness mode of dataGroups in ngsw-config.json\r\n\r\n\r\n### Describe alternatives you've considered\r\nhttps://medium.com/@sascha.wolff/how-to-use-angular-6-service-worker-for-dynamically-loading-images-f4f6f497699f\r\n","author":{"url":"https://github.com/borjapazr","@type":"Person","name":"borjapazr"},"datePublished":"2019-06-11T07:22:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/30968/angular/issues/30968"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b7d53f67-750c-5f78-956a-5da551c0433e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CEF4:3F83A1:AC697D:E6B894:6A600F1A |
| html-safe-nonce | 1e906ae4b7f4df45b53572d18fe0f7a70841a352d13bb641b0695d3c96fca73c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUY0OjNGODNBMTpBQzY5N0Q6RTZCODk0OjZBNjAwRjFBIiwidmlzaXRvcl9pZCI6IjgxODY4NDM4Mjk5MjY2MjkxNDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9797ae153933019637a0d3b3898180c1eab1500aff4982de17bb511e16a3ff5b |
| hovercard-subject-tag | issue:454521037 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/30968/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5350e3e26329f3da7fdb1c3d7a2826ee1f20952173f50ff0e9b46d04390736c5/angular/angular/issues/30968 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5350e3e26329f3da7fdb1c3d7a2826ee1f20952173f50ff0e9b46d04390736c5/angular/angular/issues/30968 |
| og:image:alt | 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 res... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | borjapazr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 48cb2ed2304f8ae5a4a05d6327faf70466c4c0d9dcbf7b9df76251ca9c669a90 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cb0f10a384099e0765239a7cc220992cae52bdba |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width