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

core(tags blocking first-paint): exclude script type=module #3676

Merged
merged 5 commits into from
Nov 3, 2017

Conversation

thisizkp
Copy link
Contributor

@thisizkp thisizkp commented Oct 28, 2017

Fixes #3359

@thisizkp thisizkp changed the title core(tags blocking first-paint): exclude script type=module from render blocking warnings core(tags blocking first-paint): exclude script type=module Oct 28, 2017
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

thanks for the contribution @thisizkp! would you mind adding a module entry to our smoketests?

<!-- FAIL: block rendering -->
<script src="./dbw_tester.js"></script>

@@ -27,12 +27,13 @@ const Gatherer = require('../gatherer');
function collectTagsThatBlockFirstPaint() {
return new Promise((resolve, reject) => {
try {
const tagList = [...document.querySelectorAll('link, head script[src]')]
const tagList = [...document.querySelectorAll('link, head script[src], script[type]')]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this added?

Copy link
Contributor Author

@thisizkp thisizkp Oct 31, 2017

Choose a reason for hiding this comment

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

to detect the inline modules, type="module" may not be always followed by the src attribute.

<script type="module">
import module from '../example.js';
module.test();
</script>

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure, but I mean we're trying to ignore modules so we'd be pulling them in just to ignore them

.filter(tag => {
if (tag.tagName === 'SCRIPT') {
return !tag.hasAttribute('async') &&
!tag.hasAttribute('defer') &&
!/^data:/.test(tag.src);
!/^data:/.test(tag.src) &&
!(tag.getAttribute('type') === 'module');
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's do tag.getAttribute('type') !== 'module'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this just for readability or anything I'm missing over?
I just wrote like this to make it consistent with the above checks

Copy link
Collaborator

Choose a reason for hiding this comment

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

well the others are like that only because there not using an operator, so yeah just easier to read :)

@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 1, 2017

@patrickhulce did those minor fixes, not sure about adding module entry to smoke tests. Can you help me out with any pointers to docs, examples or any resources about doing that?

@patrickhulce
Copy link
Collaborator

The two lines I referenced are the best example. Basically you want to copy those two lines in that file, add type="module", and change the comment to say it should pass because it's a module and is not blocking

<!-- FAIL: block rendering -->
<script src="./dbw_tester.js"></script>

@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 1, 2017

Oh, I was thinking may be I should create a new file separately to test module thing and I'm not sure about what to test out in those files. Thanks for that 👍

@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 1, 2017

@patrickhulce After that mentioned change I did (locally), smoke tests are failing. Need some more time to fix that issue. Will try and get back to you If I get stuck.

@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 2, 2017

After adding this line

<script type="module" src="dbw_tester.js?module"></script>

Smoke tests are failing for uses-http2 and mutation-events. I'm puzzled about how this change can affect that. Any help

@patrickhulce
Copy link
Collaborator

You haven't pushed your changes so I'm not sure exactly what's failing 😄 but you've added a new URL so you'll probably need to update the uses-http2 expectation to include 1 more request.

'uses-http2': {
score: false,
extendedInfo: {
value: {
results: {
length: 15,
},
},
},

(bump line 40 to 16)

mutation events is probably reporting the mutation events fired in dbw_tester.js so let's just change the URL to something that'll 404 like src="sample-module.js", keep it simpler for you :)

@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 2, 2017

but if it's just a 404, the test will not give accurate results right?

@patrickhulce
Copy link
Collaborator

patrickhulce commented Nov 2, 2017

a blocking script that 404s is still a blocking script so it should work fine for our purposes (you can add src="sample-module.js?delay=500" to make sure it takes a while to return) and it shouldn't impact any of the other expectations other than uses-http2

@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 3, 2017

blocked at this - <script type="module" src="./sample-module.js?delay=500"></script> line is being triggered twice.

'uses-http2': {
score: false,
extendedInfo: {
value: {
results: {
length: 15,
},
},
},

If I bump up this number to 17 instead of 16, it works. But I'm curious about what is triggering it.

@patrickhulce
Copy link
Collaborator

If I bump up this number to 17 instead of 16, it works. But I'm curious about what is triggering it.

Seems like chrome double requests 404 modules, so I went ahead and fixed up the smoketests since I've had you churn enough 😄

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

thanks for helping us out here @thisizkp! 🎉 🎂

@patrickhulce patrickhulce merged commit 6ba5eb1 into GoogleChrome:master Nov 3, 2017
@thisizkp thisizkp deleted the issue-3359 branch November 4, 2017 03:12
@thisizkp
Copy link
Contributor Author

thisizkp commented Nov 4, 2017

thank you for helping me out, got stuck so many times... but somehow finally merged 🎉

christhompson pushed a commit to christhompson/lighthouse that referenced this pull request Nov 28, 2017
…rome#3676)

* exclude script type='module' from render blocking warnings

* pr fixes

* add 404 sample module as script source

* quick typo fix

* fix smoketests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants