core(critical-request-chains): Remove iframe as Critical Request#3583
core(critical-request-chains): Remove iframe as Critical Request#3583patrickhulce merged 7 commits intomasterfrom
Conversation
| const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
|
||
| // Iframes are considered High Priority but they are not render blocking | ||
| const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category |
There was a problem hiding this comment.
is there an actual initiator type we can look at? what about frameId would that help us?
There was a problem hiding this comment.
parse or script I guess. Main document is set to other. What does frameid means?
There was a problem hiding this comment.
requests have a frameId associated with them, so I'm wondering if we can use that to check if the request was for a frame other than the main frame
https://chromedevtools.github.io/devtools-protocol/tot/Network/
| * @see https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0gpwNFiEP4TZS-YLRp_RuMlc | ||
| * @param {any} request | ||
| * @param {any} request | ||
| * @param {!WebInspector.NetworkRequest} |
There was a problem hiding this comment.
nit: missing mainResource name
|
|
||
| // Iframes are considered High Priority but they are not render blocking | ||
| const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category | ||
| && request.frameId !== mainResource.frameId; |
There was a problem hiding this comment.
niiiiice. let's use _frameId tho. i think that public api will be changing in our next bump.. haha.
There was a problem hiding this comment.
i just verified that the frameid of the iframe resource is the new iframe.. we're good!
| const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
|
||
| // Iframes are considered High Priority but they are not render blocking | ||
| const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category |
There was a problem hiding this comment.
the other examples in here I believe are a bit more verbose than they need to be, you should be able to just check request._resourceType === WebInspector.resourceTypes.Document
| return Runner.run({}, {url, config}).then(results => { | ||
| const audits = results.audits; | ||
| assert.equal(audits['critical-request-chains'].displayValue, 9); | ||
| assert.equal(audits['critical-request-chains'].displayValue, 5); |
There was a problem hiding this comment.
this is the good kind of test change, right? :D
(i.e. we were wrong before and now we're right)
There was a problem hiding this comment.
yes, you can see the diff here.
https://www.diffchecker.com/ec6WBOxh
As you can see we removed 3 iframes from the critical requests:
- https://www.redditmedia.com/ads/display/300x250-companion
- https://www.redditmedia.com/gtm/jail?cb=8CqR7FcToP
- https://www.redditmedia.com/ads/display/300x250
so in total we removed 5 leaf nodes but we only remove 4 chains as https://www.redditstatic.com/reddit-init.en.belOwpfqWtw.jsis still a root node.
| networkRecords[1].url = 'https://example.com/iframe.html'; | ||
| networkRecords[1].mimeType = 'text/html'; | ||
| networkRecords[1]._resourceType._category = WebInspector.resourceTypes.Document._category; | ||
| networkRecords[0].frameId = '2'; |
There was a problem hiding this comment.
is this intentional to keep changing frameId of the root document?
also is there a document request case that is within the same frame we should add to tests?
There was a problem hiding this comment.
Only html documents that are being fetched are Documents from iframe. XHR is not counted here
paulirish
left a comment
There was a problem hiding this comment.
this'll be good once it comes back. nice work
|
|
||
| // Iframes are considered High Priority but they are not render blocking | ||
| const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category | ||
| && request.frameId !== mainResource.frameId; |
There was a problem hiding this comment.
niiiiice. let's use _frameId tho. i think that public api will be changing in our next bump.. haha.
|
|
||
| // Iframes are considered High Priority but they are not render blocking | ||
| const isIframe = resourceTypeCategory === WebInspector.resourceTypes.Document._category | ||
| && request.frameId !== mainResource.frameId; |
There was a problem hiding this comment.
i just verified that the frameid of the iframe resource is the new iframe.. we're good!
| static isCritical(request) { | ||
| static isCritical(request, mainResource) { | ||
| const resourceTypeCategory = request._resourceType && request._resourceType._category; | ||
|
|
There was a problem hiding this comment.
should we add a console.assert(mainResource, 'mainResource not provided')?
we'll need https://eslint.org/docs/rules/no-console#options set up
There was a problem hiding this comment.
I could wrap it between disable statements? This is just for debugging purposes right?
There was a problem hiding this comment.
actually instead:
const assert = require('assert');
...
assert.ok(mainResource, 'mainResource not provided');| // 2nd record is an iframe in the page | ||
| networkRecords[1].url = 'https://example.com/iframe.html'; | ||
| networkRecords[1].mimeType = 'text/html'; | ||
| networkRecords[1]._resourceType._category = WebInspector.resourceTypes.Document._category; |
There was a problem hiding this comment.
along with the change above, this can now be
networkRecords[1]._resourceType = WebInspector.resourceTypes.Document;
patrickhulce
left a comment
There was a problem hiding this comment.
awesome thanks @wardpeet!
Fixes #3443
It was pretty hard after all to see if a html document was an iframe or not.
I needed this for the preload audit.