After some investigation, I updated the title of the question. Please see my updates below.
Original question:
I'm building a website with Wordpress and make sometimes use of async calls to WP REST API endpoints.
Calling this endpoints from my AJAX functions leads often to TTFB times from at least ~780ms:
But if I open the URL/endpoint directly in the browser I get TTFB times that are 4-5 time faster:
I wonder where the delays come frome. I'm running this page on my local dev server with Apache 2.4, HTTP/2 and PHP 7 enabled.
What is the best way to monitor such performance "issues"?
Please mind: I'm not using Wordpress' built-in AJAX-functionality. I'm just calling something like
axios.get(`${url}/wp-json/wp/v2/flightplan`)
inside a React component that I've mounted in my homepage-template.
Damn interesting: clearing cookies reduces TTFB a lot:
After removing the other both AJAX calls, the flightplan
request performs much faster. I think there are some issues with concurrent AJAX requests. I've read a bit about sessions locking, but since Wordpress and all of the installed plugins doesn't make use of sessions, this can't be the reason.
Definitively, it has something to do with my local server setup. Just deployed the site to a "real" webserver:
But it would still be interesting to know how to setup a server that can handle concurrent better.
I made a little test: calling 4 dummy-requests before calling the "real" ones. The script only returns a "Foobar" string. Everything looks fine at this time:
But when adding sleep(3)
to the dummy AJAX-script, all other requests takes much longer too:
Why?
Because your Ajax call will wait the loading of all your WP plugins :)
So you need to make some test without plugin, and activate one by one to see which one slow down your ajax call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With