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

Update strategy for adding script[type="text/partytown"] to worker scripts #1497

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

thelovekesh
Copy link
Member

Summary

Fixes #1468

Relevant technical choices

  • Update logic to use wp_script_add_data() to identify worker offloading scripts instead of identifying them by web-worker-offloading script dependency.

  • Update test cases.

@thelovekesh thelovekesh added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Web Worker Offloading Issues for the Web Worker Offloading plugin. labels Aug 25, 2024
@thelovekesh thelovekesh added the no milestone PRs that do not have a defined milestone for release label Aug 25, 2024
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: thelovekesh <thelovekesh@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines +85 to +86
wp_scripts()->registered[ $dep->handle ]->deps[] = 'web-worker-offloading';

Copy link
Member

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.

Suggested change
wp_scripts()->registered[ $dep->handle ]->deps[] = 'web-worker-offloading';

Comment on lines +87 to 90
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 );
}
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no milestone PRs that do not have a defined milestone for release [Plugin] Web Worker Offloading Issues for the Web Worker Offloading plugin. [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconsider approach of using script dependencies to opt-in a script for worker offloading
2 participants