I'm currently working on improving the functionality of a WordPress website using AngularJS. To achieve this, I am utilizing the WP-API (v2) plugin to create custom endpoints and consuming them on the front end with the Angular $http service.
Below is a snippet of the Angular request code:
function fetchData(slug) {
return $http.get(endpoints.specialData.replace(':slug', slug)).then(function (response) {
var data = response.data || {};
return data;
}, function (response) {
return response;
});
}
Upon inspecting the page where this call is made, I noticed that the XHR time is approximately 4.5 seconds (as per Chrome dev tools).
Interestingly, when directly accessing the same endpoint URL in the browser, the JSON result is returned in just 900ms. It's worth mentioning that the endpoint URL uses a relative path (/path/relative/from/site/root) instead of the full http:// path.
Any insights into why there might be such a significant delay when using Angular?