Ajax call on WordPress causes long TTFB – how to improve?

CONTEXT

I’m experiencing very long Time To First Byte on a WordPress page that uses Ajax to filter/load resources.

Read More

Basically, the Ajax call tells a PHP file what filter has been applied on the front end, the PHP file gets the relevant values from SQL to construct a long HTML string and then the PHP file returns this long HTML string through Ajax. This PHP file looks something like this:

enter image description here

There is quite a lot of HTML that is being returned by the Ajax call (~300KB) but I wouldn’t think that’s the issue.

QUESTION

How can I find what is causing this long TTFB? Assuming the basic sequence of steps can’t be changed, what can be done to improve TTFB?

Related posts