rankmath / seo-by-rank-math

Rank Math is a revolutionary WordPress SEO Plugin that combines the features of many SEO tools and lets you multiply your traffic in the easiest way possible :bulb: :chart_with_upwards_trend: →
https://rankmath.com
107 stars 52 forks source link

Leverage the new script API strategy feature to defer front end scripts #253

Open adamsilverstein opened 1 year ago

adamsilverstein commented 1 year ago

This PR adds the defer attribute to the front end script js/rank-math.js enqueued in includes/frontend/class-frontend.php.

Context

WordPress introduced a new strategy feature in the Script API in version 6.3. See this post for more details. Even though js/rank-math.js is only enqueued when the wp-admin bar is shown, it still seems helpful to leverage defer and switch away from the boolean in_footer setting.

Note that this PR includes a version check and slightly different behavior for 6.3 vs. 6.4 where a potential regression is fixed.

Summary

Test instructions