Optimize WordPress for REST API

I am interested in tips for optimizing WordPressā€™s response times for the REST API and Frontity in general. This is because when pulling some pages of my testing environment through Google PageSpeed, Iā€™m receiving messages about ā€˜Reduce initial server response timeā€™.

Iā€™m not sure if this problem stems from Vercel or from my WordPress installation, but it looks like installing a caching plugin for Rest responses (WP REST Cache) makes some difference.

When using Frontity, you donā€™t need a whole lot of functionality that WordPress loads by default. Iā€™m reading that WordPress loads plugins and themes even when doing a request to the REST API. So maybe some parts shouldnā€™t load? But of course you want to keep the ability to use the back-end for managing content, and the reponse of the REST API shouldnā€™t be altered by taking theme and plugins out of useā€¦ I found this plugin (Plugin Load Filter) which provides an interface for disabling any of your plugins for (among others) the REST API.

Iā€™ve also read about shortinit and tried to implement that in my testing environment. But I canā€™t really find a good to way to implement it.

How did Frontity itself optimize loading times on the WordPress side?

What weā€™re doing in our web right now is not only caching the REST API response but also the HTML. Weā€™re using Pantheon and weā€™re using their plugin Pantheon Advanced Page Cache for this, and itā€™s working really well. This way, the cache works as any other WordPress site.

Weā€™re not filtering the Rest API, but Iā€™m aware that other users have done that to improve REST API response times. But I would say that the best way to improve the performance is to have a good cache system for both the API and the HTML, so if the content doesnā€™t change, it can be served from a CDN and you donā€™t have to run everything again.

You can take a look at this post where Luis explains in a more detailed way how cache could work with Frontity, I think itā€™s pretty interesting -> Moving an Existing WordPress website with over 5000 Articles

I think the first thing to document here is the importance of cache in a Frontity project and how to use in different levels (WP, Frontend, ā€¦)

There are some issues already created for this. I have added this comment ini this issue to take this thread into account

2 Likes