-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use defer loading strategy for frontend view scripts #52536
Merged
Merged
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7e469ec
Load interactivity API scripts with defer loading strategy
westonruter 23b7aad
Load comment-reply script with defer loading strategy
westonruter aefd67a
Load search view script with defer loading strategy
westonruter f89e31a
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into a…
westonruter 3dd37c2
Defer the view scripts for the Navigation and File blocks
westonruter 4f7301b
Use DCA event instead of window load event for Navigation viewScripts
westonruter 3e7c73e
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into a…
westonruter 34faf8f
Optimize submenu-on-click view script
westonruter 5329284
Optimize modal view script
westonruter 2bafd37
Utilize asset file for wp-block--search-view
westonruter 4b86ce4
Conditionally enqueue navigation view scripts only if needed
westonruter 95beb24
Update Navigation block to remove/add view scripts in the same way th…
westonruter 404128f
Update Search block to include view script in same way as File block …
westonruter 4ccd709
Refactor Search block view script
westonruter b7863e9
Use more DOM properties instead of attributes
westonruter c41d35b
Use more precise reflected terminology
westonruter b50a2b8
Remove resolved TODO comment
westonruter a18d055
Use event delegation to open MicroModal
westonruter 712c4cf
Remove excessive type check
westonruter b2db932
Fix closing submenus when there are multiple Navigation blocks on a page
westonruter 4a7fc46
Clarify block.json comment
westonruter 7fe5534
Merge branch 'trunk' into add/defer-script-loading-strategy
westonruter ffd9e5c
Add core merge note for comment-reply script strategy
westonruter 26c06ab
Use defer strategy instead of async for Navigation and Search blocks
westonruter 86b8e36
Defer all block view scripts
westonruter aab0b4b
Ensure interactivity scripts remain in footer in WP<6.3
westonruter 73e3564
Remove defer from comment-reply for now
westonruter da2380a
Merge remote-tracking branch 'origin/trunk' into add/defer-script-loa…
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@westonruter, do we have a patch against WordPress core that sets the default strategy for
viewScripts
todefer
?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.
I'm catching up after an extended leave, so I might find the answer myself in the meantime as I'm reading the communication related to the
defer
strategy. I'm mostly willing to ensure we have better defaults in WP core, so people have performant configuration by design.At the moment, I don't see any changes applied in core:
https://github.com/WordPress/wordpress-develop/blob/f107073f39827c2ab2b3b3198e194f844f357213/src/wp-includes/blocks.php#L169-L174
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.
The patch hasn't been backported to core yet. I wasn't sure when that should be done, if it should sit in Gutenberg a bit first to test and then propose for core, or to add it to core at the same time. I'm happy to open a backport ticket and open a PR to apply this patch.
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.
Opened Core-59115 and WordPress/wordpress-develop#5019
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.
Committed to core: r56398
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.
Let's enable it for all blocks in both the Gutenberg plugin, and in WordPress core to get as much testing as necessary with 3rd party blocks that use
block.json
. I see that you discussed it in the context of view scripts in #52536 (comment) and ruled out as a potential issue.Noting that with this patch,
defer
is going to be used witheditorScript
,script
, andviewScript
. In the case ofeditorScript
, the dependencies aren't usingdefer
likewp-block
orwp-block-editor
so it will probably fallback to the legacy handling. I'll comment on Trac, too.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.
Yes, it should be enabled for all blocks, whether core or 3rd party.
Oh, good catch!