-
Notifications
You must be signed in to change notification settings - Fork 237
Add unique identifier to "PerformanceResourceTiming" API #1007
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for working on this! I'm a bit confused about how the solution (specifically option 1) maps to the use case. This OP alludes to that but this explainer doesn't... Another issue with this is that mapping a response to a |
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.
Looks like both files are almost identical. I assume we only need one of them?
The payload of a performance.getEntriesByType("resource") or performance.getEntriesByType("navigation") call would then look like: | ||
|
||
``` | ||
requestId: “123e4567-e89b-12d3-a456-426614174000” |
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.
Please replace smart quotes with regular quotes.
requestId: “123e4567-e89b-12d3-a456-426614174000” | |
requestId: "123e4567-e89b-12d3-a456-426614174000" |
Or | ||
|
||
fetch('https://api.example.com/data', { | ||
method: ‘GET’, |
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.
Please fix smart quotes
method: ‘GET’, | |
method: 'GET', |
[Would like a precise way to map PerformanceTimings to FetchEvent](https://github.com/w3c/resource-timing/issues/259) | ||
|
||
## Introduction | ||
[Resource Timing](https://www.w3.org/TR/resource-timing/) API has no information that uniquely identifies each resource timing to each fetch request. As such, in situations where resources are fetched multiple times, such as with multiple tabs or multiple requests to the same URL, it’s not possible to accurately map resource timings. This lack of clear mapping can hinder performance analysis and optimization efforts. |
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.
[Resource Timing](https://www.w3.org/TR/resource-timing/) API has no information that uniquely identifies each resource timing to each fetch request. As such, in situations where resources are fetched multiple times, such as with multiple tabs or multiple requests to the same URL, it’s not possible to accurately map resource timings. This lack of clear mapping can hinder performance analysis and optimization efforts. | |
The [Resource Timing](https://www.w3.org/TR/resource-timing/) API has no information that uniquely maps each resource timing to each fetch request. As such, in situations where resources are fetched multiple times, such as with multiple tabs or multiple requests to the same URL, it’s not possible to accurately map resource timings. This lack of clear mapping can hinder performance analysis and optimization efforts. |
|
||
## Use Cases | ||
Tracking resource timing across multiple requests, whether from different browsing contexts (e.g. multiple tabs) or service workers, can be challenging. Some examples include: | ||
1. **Measuring Resource Timing Across Client and Service Worker** <br> |
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.
This <br>
and the next <br>
look weirdly out of place as the only embedded HTML in the document. Can you replace with an additional newline?
## Use Cases | ||
Tracking resource timing across multiple requests, whether from different browsing contexts (e.g. multiple tabs) or service workers, can be challenging. Some examples include: | ||
1. **Measuring Resource Timing Across Client and Service Worker** <br> | ||
When multiple tabs request the same resource through a service worker, associating timing data between the Performance Resource Timing entries observed in the client and those within the service worker can be difficult. The client-side performance.getEntries() provide the total duration of the request, but it lacks insight into processes inside service worker, such as request handling and network retrieval. The service worker itself can collect performance timing for fetch requests, but there is no direct linkage between these entries and those in the client’s performance timeline. |
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.
When multiple tabs request the same resource through a service worker, associating timing data between the Performance Resource Timing entries observed in the client and those within the service worker can be difficult. The client-side performance.getEntries() provide the total duration of the request, but it lacks insight into processes inside service worker, such as request handling and network retrieval. The service worker itself can collect performance timing for fetch requests, but there is no direct linkage between these entries and those in the client’s performance timeline. | |
When multiple tabs request the same resource through a service worker, associating timing data between the Performance Resource Timing entries observed in the client and those within the service worker can be difficult. The client-side `performance.getEntries()` provides the total duration of the request, but it lacks insight into processes inside the service worker, such as request handling and network retrieval. The service worker itself can collect performance timing for fetch requests, but there is no direct linkage between these entries and those in the client’s performance timeline. |
event.respondWith((async () => { | ||
const response = await fetch(event.request); | ||
const entries = self.performance.getEntriesByType("resource"); | ||
const timing = entries.find(e => e.responseId === response.responseId); |
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.
All of the sample code in this document contains code something like this
const entries = self.performance.getEntriesByType("resource");
const timing = entries.find(e => e.responseId === response.responseId);
Should we also be proposing a new Performance function to help find these entries?
partial interface Performance {
PerformanceEntry getEntryById (DOMString id);
}
const timing = self.performance.getEntryById(response.responseId);
Adding a read-only `requestId` field on the Request interface. | ||
|
||
```webidl | ||
[ Exposed=Window, Worker ] |
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.
[ Exposed=Window, Worker ] | |
[Exposed=(Window,Worker)] |
```js | ||
self.addEventListener('fetch', event => { | ||
const request = event.request; | ||
console.log(request.requestId); '123e4567-e89b-12d3-a456-426614174000' |
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.
console.log(request.requestId); '123e4567-e89b-12d3-a456-426614174000' | |
console.log(request.requestId); // '123e4567-e89b-12d3-a456-426614174000' |
Adding a read-only 'requestId' field on the Response interface. | ||
|
||
```webidl | ||
[ Exposed=Window, Worker ] |
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.
[ Exposed=Window, Worker ] | |
[Exposed=(Window, Worker)] |
|Distinguish between identical requests from different clients. | ✅ |✅ | ✅ | | ||
|Enables end-to-end correlation between requests, responses, and resource timings.| ❌ |✅| ❌ | | ||
|Leverages existing identifiers (FetchEvent).| ❌ | ❌ | ✅ | | ||
|Developers do not need to generate and manage RequestIds | ✅ |❌| ✅ | |
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.
For option 2 I thought the request ID is optional and will be generated by the user agent if not provided? If so then 'Developers do not need to generate manage RequestIds' for option 2 is true - they don't need to. Maybe this row is supposed to be about removing flexibility for end devs to use their own IDs?
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.
LGTM after pending comments are addressed.
Explainer doc for the feedback.