-
Notifications
You must be signed in to change notification settings - Fork 174
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
RuntimeCaching.strategyOptions.cacheExpiration is deprecated in Workbox v3 #336
Comments
Hi @Yihao-G. Do you mind making a PR for updating? |
@pi0 I'm happy to make a PR but how would we implement it? Currently I have this type declaration: import { Plugin as BackgroundSyncPlugin } from 'workbox-background-sync'
import { Plugin as BroadcastUpdatePlugin } from 'workbox-broadcast-update'
import { Plugin as CacheableResponsePlugin } from 'workbox-cacheable-response'
import { Plugin as ExpirationPlugin } from 'workbox-expiration'
import { Plugin as RangeRequestsPlugin } from 'workbox-range-requests'
import { WorkboxPlugin } from 'workbox-core'
export type RuntimeCaching = {
urlPattern: string,
handler?: CachingStrategy,
methods?: HTTPMethod,
strategyOptions?: {
cacheName: string,
plugins?: StrategyPlugin[]
}
}
export type StrategyPlugin = BackgroundSync
| BroadcastUpdate
| CacheableResponse
| Expiration
| RangeRequests
| WorkboxPlugin
export interface BackgroundSync {
use: 'BackgroundSync',
config: ConstructorParameters<typeof BackgroundSyncPlugin>
}
export interface BroadcastUpdate {
use: 'BroadcastUpdate',
config: ConstructorParameters<typeof BroadcastUpdatePlugin>
}
export interface CacheableResponse {
use: 'CacheableResponse',
config: ConstructorParameters<typeof CacheableResponsePlugin>
}
export interface Expiration {
use: 'Expiration',
config: ConstructorParameters<typeof ExpirationPlugin>
}
export interface RangeRequests {
use: 'RangeRequests',
config: ConstructorParameters<typeof RangeRequestsPlugin>
} By doing so, users don't need to import these plugins, and the Am I worried too much? The current config implementation doesn't allow users to access plugin methods anyway... What do you think? |
…ng a strategy (#337) * Initial implementation of #336 * Update types * Fix test The strategy constructor option object can be optional as shown here: https://developers.google.com/web/tools/workbox/modules/workbox-strategies * Fix broken generated sw.js * Remove unused field * Typo fixes * Correct RuntimeCaching type * Added tests * Fix code * Revert "Added tests" partially This reverts commit d467e17 * Do not directly generate runtime code from nuxt.config #337 (comment) * Template formatting and remove unnecessary replace in toCode function * simplify toCode function * refactor: use runtime code instead of codegen Co-authored-by: pooya parsa <pyapar@gmail.com>
…ng a strategy (#337) * Initial implementation of #336 * Update types * Fix test The strategy constructor option object can be optional as shown here: https://developers.google.com/web/tools/workbox/modules/workbox-strategies * Fix broken generated sw.js * Remove unused field * Typo fixes * Correct RuntimeCaching type * Added tests * Fix code * Revert "Added tests" partially This reverts commit d467e17 * Do not directly generate runtime code from nuxt.config #337 (comment) * Template formatting and remove unnecessary replace in toCode function * simplify toCode function * refactor: use runtime code instead of codegen Co-authored-by: pooya parsa <pyapar@gmail.com>
Workbox has deprecated the use of
cacheExpiration
as a parameter of the strategies classes inworkbox-strategies
module. The constructor style Plugins are suggested. As described on this page:In our
sw.js
template, we are still using the old-style way to set up plugins usingJSON.stringify
to serialise the entirestrategyOptions
(not sure whether this is still working in v5). Also because of the use ofJSON.stringify
, incorporating the new way is not possible in the Nuxt config file.Furthermore, the TypeScript declaration also contains the old
cacheExpiration
field.The documentation also contains the old way to set up plugins for Workbox Strategies.
The text was updated successfully, but these errors were encountered: