-
Notifications
You must be signed in to change notification settings - Fork 822
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
Feature/recipes precache and normalize #2718
Feature/recipes precache and normalize #2718
Conversation
Takes an array of items and a Workbox Strategy and warms the strategy’s cache with those items at install. Useful for getting specific items into cache but allowing them to be updated outside of the Service Worker install cycle
Give users of page/image/resource recipes the ability to warm those caches using warmStrategyCache functionality. Also allows them to include plugins if desired (for instance, to normalize URLs coming into the cache)
While precache will still work, and that will be tried first, the files will be saved in a workbox-offline-fallbacks cache and the cache will try to be retrieved from there if precache fails.
I'm not sure what the error in the Mac test suite is, and why the Windows one didn't fail. If someone can point me to what I need to fix I'd be more than happy to fix it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I still need to give some of the modified files a more complete review, but here's some feedback on the new file.
*/ | ||
function warmStrategyCache(options: WarmStrategyCacheOptions): void { | ||
self.addEventListener('install', event => { | ||
const warm = options.paths.map(path => options.strategy.handleAll({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think done
(or donePromises
) would be a more descriptive variable name than warm
, especially since it's not entirely obvious from reading the code that the [1]
index represents a done
promise.
import './_version.js'; | ||
|
||
export interface WarmStrategyCacheOptions { | ||
paths: Array<string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you switch from calling this paths
to urls
?
(As far as I can tell, you should be able to pass in any absolute or relative URL inside this array, right?)
Co-authored-by: Jeffrey Posnick <jeffy@google.com>
Improves clarity of each, pre PR review request
@jeffposnick Looks like test are passing now. Here's the Workbox Recipes docs update to go along w/this |
R: @jeffposnick @philipwalton
warmStrategyCache
, which takes an array of paths and a Workbox strategy and warms that strategy's cache with those paths at service worker install time.warmCache
option to page, image, and static resource recipes to allow users to warm those cachesplugins
option to page, image, and static resource recipes to allow users to pass additional plugins to those recipes, allowing a user, for instance, to add a URL normalization plugin to the page recipe