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

fix sw caching #326

Merged
merged 2 commits into from Jan 10, 2017
Merged

Conversation

sebastianbenz
Copy link
Collaborator

No description provided.

@andreban andreban added the LGTM label Jan 10, 2017
@andreban
Copy link
Member

LGTM. I can't seem to find the review button on the UI anymore. Am I the only one missing it?

.map(cacheName => caches.delete(cacheName))
).then(self.clients.claim())
self.addEventListener('activate', event =>
event.waitUntil(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to waitUntil() the previous caches are cleared—that should be able to happen async. What looks more suspicious to me is that clients.claim() does not happen immediately. I think we should be calling clients.claim() when we enter the activate event—the cache should be in a good state at that point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True - as our sw only accesses the latest version of the cache now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

.then(cache => cache.match(request))
.then(response => {
const index = this._pagesBeingLoaded.indexOf(request.url);
this._pagesBeingLoaded.splice(index, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really for this PR but why is _pagesBeingLoaded modified here? It looks like this keeps track of "in-flight" requests and so I would expect it to be modified when the response is received, but instead it seems to be modified when fetchWithPageTransition() is called a second time with the same request??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to support Gulliver's network first strategy -> only return the cached version if a loading page has been requested before. This is not a perfect solution as it can't handle (theoretical) parallel requests to the same page.

@sebastianbenz
Copy link
Collaborator Author

PTAL

@ithinkihaveacat
Copy link
Collaborator

LGTM

@sebastianbenz sebastianbenz merged commit 52cda61 into GoogleChromeLabs:master Jan 10, 2017
@sebastianbenz sebastianbenz deleted the sw-caching-fix branch January 10, 2017 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants