-
Notifications
You must be signed in to change notification settings - Fork 95
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
Update strategy for adding script[type="text/partytown"]
to worker scripts
#1497
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
wp_scripts()->registered[ $dep->handle ]->deps[] = 'web-worker-offloading'; | ||
|
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 don't think we technically have to do this because when a script is made into a text/partytown
script, it won't by definition do anything until the Partytown script has been loaded on the page. So the Partytown script could be located anywhere (and ideally it should always be in the footer!) But I suppose the benefit of doing this way is it would get added automatically. Still I think there could be a wp_print_footer_scripts
action that checks if any of the enqueued scripts require WWO, and if so, it could then ultimately print the Partytown script in the footer.
wp_scripts()->registered[ $dep->handle ]->deps[] = 'web-worker-offloading'; |
if ( false === wp_scripts()->get_data( $dep->handle, 'strategy' ) ) { | ||
wp_script_add_data( $dep->handle, 'strategy', 'async' ); // The 'defer' strategy would work as well. | ||
wp_script_add_data( $dep->handle, 'wwo_strategy_added', true ); | ||
} |
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.
We may need to end up removing this logic if we are going to rely on inline after scripts also being made Partytown scripts as mentioned in #1455. But that can be done in another PR.
Summary
Fixes #1468
Relevant technical choices
Update logic to use
wp_script_add_data()
to identify worker offloading scripts instead of identifying them byweb-worker-offloading
script dependency.Update test cases.