-
Notifications
You must be signed in to change notification settings - Fork 798
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
In Likes and Comment Likes modules, prevent blocking page load with 2 scripts #14841
Conversation
These both depend on jquery, so this could remove even another script from blocking rendering.
This is an automated check which relies on |
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.
@kienstra The changes look good, I've verified the scripts get loaded before the https://widgets.wp.com/likes/master.html
iframe (which depends of them being loaded) in the footer.
I'd suggest we make the same change in the sibling comment-likes.php
module as well. These two seem the only ones to pull those scripts in.
Nice, thanks for reviewing this.
Oh, good idea. |
As Dan raised, this should not enqueue this JS if this isn't in the document.
This PR now addresses #13929 (comment) for the Likes and Comment Likes modules. It prevents the JS from being enqueued when Likes are disabled for a post or globally. Steps To Test
|
Don't enqueue scripts if likes aren't enabled, and move the dependencies to the footer, as the script that depends on them, 'jetpack_likes_queuehandler', is in the footer. It doesn't seem necessary for these to be above the footer.
It should ensure that the styles are present, not that they aren't.
Request For Review Hi @dero,
Could you please review this again, now that it addresses your suggestion? It also addresses issue #13929 Thanks, Dero! |
Has it been confirmed that this change of moving the script to the footer impacts how quickly the page renders? I ask because in general moving a script tag to the bottom of the page will not change the impact in terms of render blocking. Browsers like Chrome will quickly scan the HTML looking for resources it thinks will be important to rendering the page and loads them early on, mainly CSS and JS. Even if they are listed at the very bottom of the page. You can see that happening with this test - https://www.webpagetest.org/result/200304_1E_35a21961f2be5996d4a1613a687f7c3b/1/details/#waterfall_view_step1 - the third request in the page load was from a script tag at the bottom of the page ( bundle.js ). Specifically line 1333, out of 1436 lines. |
Hi @josephscott, No, I haven't tested the performance difference between passing the 5th That's a general best practice, but you're probably right that it's not a big impact. I'll look at it in more detail. |
Performance impact of moving scripts to footerHi @josephscott, Like you mentioned, the performance benefit of only moving the scripts to the footer looks small. In 10 trials, the average time to First Contentful Paint was 3.15 with the scripts moved to the footer, as opposed to 3.4 with them above the footer. But most of that difference is from outliers. The most common case is that there is no difference. Steps to reproduce
diff --git a/modules/comment-likes.php b/modules/comment-likes.php
index 8868f2688..4332e8eb5 100644
--- a/modules/comment-likes.php
+++ b/modules/comment-likes.php
@@ -142,7 +142,7 @@ class Jetpack_Comment_Likes {
Assets::get_file_url_for_environment( '_inc/build/postmessage.min.js', '_inc/postmessage.js' ),
array( 'jquery' ),
JETPACK__VERSION,
- true
+ false
);
wp_enqueue_script(
'jetpack_resize',
@@ -152,7 +152,7 @@ class Jetpack_Comment_Likes {
),
array( 'jquery' ),
JETPACK__VERSION,
- true
+ false
);
wp_enqueue_script( 'jetpack_likes_queuehandler', plugins_url( 'likes/queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize' ), JETPACK__VERSION, true );
}
diff --git a/modules/likes.php b/modules/likes.php
index 4a0b0273a..f4d3f683d 100644
--- a/modules/likes.php
+++ b/modules/likes.php
@@ -296,7 +296,7 @@ class Jetpack_Likes {
Assets::get_file_url_for_environment( '_inc/build/postmessage.min.js', '_inc/postmessage.js' ),
array( 'jquery' ),
JETPACK__VERSION,
- true
+ false
);
wp_register_script(
'jetpack_resize',
@@ -306,7 +306,7 @@ class Jetpack_Likes {
),
array( 'jquery' ),
JETPACK__VERSION,
- true
+ false
);
wp_register_script(
'jetpack_likes_queuehandler',
ResultsFirst Contentful Paint in seconds
Average
Difference0.25 seconds, on average |
@josephscott In my understanding speculative parsing is only a heuristic that is supposed to "guess" which assets will be needed for page construction and thus it only affects the timing of network requests. The synchronous script execution still blocks the HTML parser and thus introduces delays in page render. To verify this, I've inspected the main thread tasks sequence on On
On this branch:
Based on this experiment, I'd say we can conclude that:
cc @kienstra |
@dero now this is what I like! When a claim is made about performance, it needs to be confirmed. |
Yeah, thanks a lot for your really detailed look at this! 😄 |
Caution: This PR has changes that must be merged to WordPress.com |
r203942-wpcom |
* Initial changelog entry * Changelog: add #14904 * Changelog: add #14910 * Changelog: add #14913 * Changelog: add #14916 * Changelog: add #14922 * Changelog: add #14924 * Changelog: add #14925 * Changelog: add #14928 * Changelog: add #14840 * Changelog: add #14841 * Changelog: add #14842 * Changelog: add #14826 * Changelog: add #14835 * Changelog: add #14859 * Changelog: add #14884 * Changelog: add #14888 * Changelog: add #14817 * Changelog: add #14814 * Changelog: add #14819 * Changelog;: add #14797 * Changelog: add #14798 * Changelog: add #14802 * Changelog: add #13676 * Changelog: add #13744 * Changelog: add #13777 * Changelog: add #14446 * Changelog: add #14739 * Changelog: add #14770 * Changelog: add #14784 * Changelog: add #14897 * Changelog: add #14898 * Changelog: add #14968 * Changelog: add #14985 * Changelog: add #15044 * Changelog: add #15052 * Update to remove Podcast since it remains in Beta * Changelog: add #14803 * Changelog: add #15028 * Changelog: add #15065 * Changelog:add #14886 * Changelog: add #15118 * Changelog: add #14990 * Changelog: add #14528 * Changelog: add #15120 * Changelog: add #15126 * Changelog: add #15049 * Chanegelog: add #14852 * Changelog: add #15090 * Changelog: add #15138 * Changelog: add #15124 * Changelog:add #15055 * Changelog: add #15017 * Changelog: add #15109 * Changelog: add #15145 * Changelog:add #15096 * Changelog:add #15153 * Changelog: add #15133 * Changelog: add #14960 * Changelog: add #15127 * Changelog: add #15056 * Copy current changelog to changelog archive. * Clarify changelog description
Fixes #13929
Changes proposed in this Pull Request:
wp_enqueue_script()
the 5th$in_footer
argument oftrue
, to prevent the scripts from blocking the page loadIs this a new feature or does it add/remove features to an existing part of Jetpack?
Testing instructions:
Proposed changelog entry for your changes: