headstartwp icon indicating copy to clipboard operation
headstartwp copied to clipboard

Reduce Yoast overhead by removing and preventing additional queries for Yoast metadata

Open nicholasio opened this issue 2 years ago • 0 comments

Is your enhancement related to a problem? Please describe.

We recently did some work to reduce the Yoast payload and optimize hydration but there's still room for improving performance by preventing Yoast from doing a lot of additional queries on WP by disabling these additional queries in the Plugin.

We don't need every post to have an associated yoast_head and yoast_head_json. We only need the first post and the associated queried object to have Yoast metadata.

Bellow are examples of different scenarios and which entities would need the yoast metadata.

Scenarios

Scenario 1

If we're querying for { postType: 'post', slug: 'hello-world' }. Only the first post needs Yoast metadata, There's no queriedObjected on this request so metadata on associated terms can be removed as well.

Scenario 2

If we're querying for { postType: 'post', per_page: 10, category: 'news' }, only the first post and the first term of the news category needs the yoast metadata.

Scenario 3

If we're querying for { postType: 'post', per_page: 10, author: 'jane' }, only the first post and the jane author needs the yoast metadata.

Scenario 4

If we're querying for { postType: 'post', per_page: 10, category: 'news', author: 'jane' }, only the first post. the jane author needs the first term of the news category needs the yoast metadata.

Implementation

We can activate this optimization via headless.config.js.

module.exports = {
	integrations: {
		yoastSEO: {
			enable: true,
                        optimizeYoastPayload: true,
		},
	},
}

Then if optimizeYoastPayload is true our fetch strategies would send a optimizeYoastPayload query param to all requests which would enable the plugin code to optimize yoast metadata. This allows the optimization to be controlled by the front-end versus having to activate via a filter/setting in WP.

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

nicholasio avatar Jul 18 '23 15:07 nicholasio