w3c / navigation-timing

Navigation Timing
https://w3c.github.io/navigation-timing/
Other
116 stars 30 forks source link

A scenario where transferSize is 0 for non cached loads (or may be not) #146

Closed Nithanaroy closed 2 years ago

Nithanaroy commented 3 years ago

On LinkedIn Lite, I wish to change the app's functionality based on whether the current page was loaded from cache or network. As per https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize, transferSize === 0 should be a safe way to estimate this. But in situations when the user clicks on the link that is still being cached, Chrome reports the transferSize to be 0, even though it was downloaded from the network. Is there a native way to filter out these cases as non-cache loads?

npm1 commented 3 years ago

@yoavweiss may know why we'd report 0 when it's not cached. It might be useful to provide a way to reproduce this issue

Nithanaroy commented 3 years ago
  1. Programmatically initiate request r1 for url1, that can be cached
  2. r1 queued by the browser
  3. User clicks the url1 which initiates r2
  4. Browser links the requests r1 and r2 and doesn't make a new network request
  5. Once r1's response is cached, r2's response is delivered from the cache

is the sequence of events I observed.

Nithanaroy commented 3 years ago

In the attached screencast, the transfer size is as expected when the user goes to Notifications page after it was fully cached.

https://user-images.githubusercontent.com/670556/115826065-33ea3480-a3bf-11eb-8878-0bfaaeb3c164.mp4

Nithanaroy commented 3 years ago

This screencast shows the tricky case, where the user navigates to Notifications page before it is fully cached. The transferSize also shows zero here. As a developer, is there a native way to differentiate this from the above happy case?

https://user-images.githubusercontent.com/670556/115825863-dce45f80-a3be-11eb-862a-bcba42ce2206.mp4

yoavweiss commented 3 years ago

@Nithanaroy - This seems like a Chromium issue, rather than a spec issue. Can you file a crbug?

Nithanaroy commented 3 years ago

@yoavweiss, filed one at https://bugs.chromium.org/p/chromium/issues/detail?id=1228610 I'm not sure though if they'll consider as technically spec doesn't enforce any behavior in this corner case. What Chromium is doing is a nice optimization to link r1 and r2 for better performance, instead of starting r2 from scratch.

yoavweiss commented 3 years ago

"they" == @npm1 and me :)

If after looking at this we'd see that there's spec clarifications to be made, we'd come back here with those conclusions.

noamr commented 3 years ago

See here.

Maybe we should clarify in a non-normative note that changing the cache state of a stored response should not affect the original response? It's not entirely clear in HTTP caching what it means to store a response, and which of its property are kept/lost with serialization.

yoavweiss commented 2 years ago

@noamr - Is the Fetch spec clarifying request coalescing beyond this bit on the HTTP cache? IIUC, the scenario we have here is that we have 2 requests that are being coalesced by the network, and I'm not sure what we should do here is properly defined and tested.

noamr commented 2 years ago

@noamr - Is the Fetch spec clarifying request coalescing beyond this bit on the HTTP cache? IIUC, the scenario we have here is that we have 2 requests that are being coalesced by the network, and I'm not sure what we should do here is properly defined and tested.

https://github.com/whatwg/fetch/pull/1329 is the first step in addressing this. This sort of issue is, generally speaking, part of the confusion caused by not being clear about whether a RT entry describes a response or a fetch. We clarified in the WG call that an RT entry describes a fetch - which means that if a response is reused by two fetches, the first one should have a transferSize and the second one shouldn't.

However, the issue specifically with response coalescing is that it's not a standard feature, but rather a Chromium implementation detail. So I would suggest to identify this behavior is a Chrome bug.

yoavweiss commented 2 years ago

I think there's no spec issue here, just an implementation bug, so closing for now. Let's re-open if we discover there are clarifications to be made.