Skip to content
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

Pause prefetches when non-prefetch request is sent to origin #45

Merged
merged 8 commits into from
Feb 27, 2020

Conversation

kevhender
Copy link
Contributor

No description provided.

@kevhender kevhender added the enhancement New feature or request label Feb 11, 2020
@kevhender
Copy link
Contributor Author

Updated per prior comments, and tests added.

// until the request finishes, then resumes prefetching
abortPrefetches()
event.respondWith(
fetch(event.request).then(resp => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to also resume in a cache block here, so that prefetches can be resumed if the last fetch fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a catch, and a test for that case.

Comment on lines 256 to 262
resumePrefetches()
}
return resp
})
.catch(e => {
if (toResume.size) {
resumePrefetches()
Copy link
Contributor

@leotoll leotoll Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess resumePrefetches can be moved to finally, then there would be no code duplication and no need for catch clause, maybe I am wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to do that, we would need to rewrite this using async/await instead of promises, which we should, as I believe those are natively supported in the service worker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@kevhender
Copy link
Contributor Author

Fixed the merge conflicts, this should be good to go now.

@kevhender kevhender merged commit 82390f8 into master Feb 27, 2020
@kevhender kevhender deleted the kh-sw-pause branch February 27, 2020 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants