-
Notifications
You must be signed in to change notification settings - Fork 104
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
Integrate Web Worker Offloading with Rank Math SEO #1685
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. |
95feeb2
to
21ee145
Compare
Thanks to @joemcgill for offering to connect with someone to test. |
Build for testing: web-worker-offloading.zip |
@westonruter @joemcgill, one of my community friends, @kafleg, is a sponsored contributor working with Rank Math SEO. I recently reached out to him, and he’s happy to help us test these integrations. Ganga, please let us know your findings or if you need anything from us. |
We tested this PR and it is working as expected. Thank you |
add_filter( 'plwwo_configuration', 'plwwo_rank_math_configure' ); | ||
|
||
/* | ||
* Note: The following integration is not targeting the \RankMath\Analytics\GTag::enqueue_gtag_js() code which is only |
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.
thanks for adding this comment!
* | ||
* @since n.e.x.t | ||
* @access private | ||
* @link https://github.com/rankmath/seo-by-rank-math/blob/c78adba6f78079f27ff1430fabb75c6ac3916240/includes/modules/analytics/class-gtag.php#L161-L167 |
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.
assume this is a "permalink"?
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.
It's a @link
to show what part of RankMath this code is related to.
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.
right, I meant the github link is from the 'copy permalink' menu:
I get https://github.com/rankmath/seo-by-rank-math/blob/6d081340b126ea80232b0bafa295ede6fa69430b/includes/modules/analytics/class-gtag.php#L161-L167 for that on master
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 believe using this type of link makes it work even if the code is moved or deleted.
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.
Oh yes, sorry, exactly. I forgot that GitHub used the "permalink" term. So yes, this link ensures that the code reference doesn't change when changes are added.
* @return array|mixed Filtered inline script attributes. | ||
*/ | ||
function plwwo_rank_math_filter_inline_script_attributes( $attributes ) { | ||
if ( isset( $attributes['id'] ) && 'google_gtagjs-inline' === $attributes['id'] ) { |
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.
noting this function is exactly the same as the previous one other than this string. probably fine, but if they got any more complex it would make sense to combine them somehow.
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, although the previous function is targeting wp_script_attributes
whereas this one is targeting wp_inline_script_attributes
, so I think they would make sense separate in any case.
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.
Lovely!
Summary
Previously #1563 to integrate Web Worker Offloading with WooCommerce.
This integrates Rank Math SEO's Google Analytics integration with Partytown to offload
gtag()
to a worker. Inline scripts now no longer block a registered script from being offloaded to a worker; any associated inline scripts are also offloaded to a worker.This is part of #1455.
Diff of Prettier-formatted page with plugin active
Looking at the network logs:
Without plugin active:
With plugin active:
Relevant technical choices
The integration is not targeting the
\RankMath\Analytics\GTag::enqueue_gtag_js()
code which is only used for WP<5.7. In WP 5.7, thewp_script_attributes
andwp_inline_script_attributes
filters were introduced, and Rank Math then deemed it preferable to usewp_print_script_tag()
andwp_print_inline_script_tag()
rather thanwp_enqueue_script()
andwp_add_inline_script()
, respectively. Since Web Worker Offloading requires WP 6.5+, there is no point to integrate with the pre-5.7 code in Rank Math.