The most performant way of fetching remote API data is not fetching it at all. Thus, use Transients API or WP Object Cache to save your computed results for future use and avoid calling external API (and further computations) on every subsequent request. Additionally, fetching, invalidating and regeneration of this data can be done in the background, but that’s more of an advanced technique and will heavily depend on your current architecture and specific use case.
The 50ms vs 500ms difference comes from:
- connecting to your own ajax endpoint
- loading and executing part of WordPress engine
- connecting, sending the request to external API endpoint and getting the response back (that 50ms, more or less)
- parsing the response
- your custom computational logic
Most time is spent on the first 3 steps, not the last 2. You can profile your code to see the full picture.
Related Posts:
- ASP.NET MVC controller actions that return JSON or partial html
- How to cache json with wp-super cache
- Why use wp_send_json() over echo json_encode()?
- Is there a JavaScript API? How to access public and private data in JS?
- WordPress function that makes HTML safe to be sent via AJAX request
- AJAX request from Chrome Extension to WordPress Website
- WP REST API route request explain
- fetching via fetch/ajax gutenberg block data from third party
- How to use wp_send_json_error?
- wp_localize_script escaping my url – fix or alternative
- How to add WP API and JS featured image attachment
- Implementing an AJAX POST API call in wordpress
- I have to post data by AJAX in wordpress to another Website
- json encode not work in wordpress
- Unable to parse JSON response from wp_send_json_success [closed]
- Ajax store response json in variables
- How do I query posts by a sub value with the API?
- Cache wp-json/posts without a plugin?
- Exposing data using a custom WordPress API
- Use WP admin AJAX url to hide API key
- merge wp rest api query to get posts per category does not work
- Retrieve JSON file from JS trough php
- Upload data from weather station to WordPress Website
- Sql formatting for post data within function
- How can I call an api before user login
- How can I wp_send_json data?
- Full Front End, AJAX comment system and comment reply script
- Send checkbox status with Ajax / JSON and save it
- Chained ajax call, second call returns 0
- Display full WordPress post under search form using AJAX
- Can I use application/json content type in WordPress
- Using wp_send_json_success instead of $result[‘message’], die, etc
- AJAX POST Value not being returned – WordPress – AutoTrader API
- Ajax call works for logged in users and returns “Bad Request” for guests [duplicate]
- How to inject data content from external json into a modal, using UIkit?
- Daily automatic update of stock quotes via REST API and Cronjob. Or is there a more sophisticated way?
- how to correctly use json_encode with ajax
- WorddPress website admin part not working correctly – I think ajax/json issue
- 403 error for ajax POST request
- Ajax WordPress pass post URLs
- How to populate data from JSON using AJAX in TypeScript? [closed]
- WordPress Ajax JSON success return no being recognized
- Ajax contact form returnig 0
- AJAX Call in Plugin Returns More than JSON
- Usage of wp_send_json_success and wp_redirect at the same time
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- How to submit a button automatically after every scheduled hours?
- jQuery’s .on() method combined with the submit event
- Why is die() used at the end of function that handles an Ajax request?
- Making my AJAX powered WordPress Crawlable
- Why is a 500 error generated by admin-ajax.php not going into the Apache error log?
- admin-ajax.php doesn’t work when using POST data and Axios
- Custom Form with Ajax
- How to process ajax requests correctly using ajax plugins
- How to get featured post title & image using JSON API?
- How is it possible that the function of the test page works, but it does not go live?
- get_posts empty when called via Ajax
- WP-API and Basic Auth returning 403 on POST but not GET
- Get Plugin Information from Multiple Sites Externally
- Is there a hook to process a backbone restful PUT request inside wordpress?
- Keep user’s privileges on accessing contents in JSON response
- How to localized one js file for different actions?
- WordPress Ajax Problems
- woocommerce registration form with klaviyo(don’t work with current user)
- Force redirect not logged in user to (wp-login.php or wp-admin) for specific page
- Getting back to ajax search results from a page
- Updating a checkbox value to database for specific row in table
- WordPress Ajax Not Working ( Custom Admin page)
- Load JavaScript from a post that’s loading into Fancybox via ajax
- Gravity form Load By Ajax Cannot Submit – Error 400
- What is the best way to do MyAjax error and success handling?
- Gravity Forms closes my popup on Validation Error [closed]
- Uncaught ReferenceError: the_ajax_script is not defined . How is this not defined?
- I can’t get a return value from Ajax
- WordPress AJAX return 0 – My case
- Creating an auto result search bar
- update_option is not saving an array, but saving the string ‘Array’
- Ajax call in wordpress not working for subscriber user
- Ajax call in WordPress – unable to display the data on the page
- How to retrieve WP_Object that is inside an array of another array
- What WP-API authentication method should I use to interact with anonymous / not-logged visitors?
- How to call ajax in plugin file
- javascript onClick update user_meta from jquery.ajax
- How to ignore WP_ERROR caused by “get_the_excerpt” method in an AJAX call?
- WP_Query is not received in Ajax
- How do I mitigate replay attacks when talking about actions that shouldn’t happen twice?
- exclude particular category in api
- How to receive JSON payload from a digital device
- Updating Jquery object with newly created elements after AJAX call
- Ajax call from Plugin using Class
- enqueue style using admin-ajax.php
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Update user meta via ajax from frontend, saving issue
- How to get the admin page slug using wp_loaded hook?
- Edit user meta on front-end via AJAX
- How to paginate Ajax result
- Tie the sending of an ajax request to WordPress hooks
- AJAX: admin-ajax.php is adding extra content to my script’s response – how to exclude header, footer, etc.?
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- wordpress ajax bad request 400