I have a gutenberg dynamic block that makes a request to an external api to return certain data to be rendered on the front. However, there are posts that have more than 15 blocks, that is, there are 15 requests and consequently this slows down the site. Is there any way to optimize this request?
Below is the function today that returns the data
Function
function requestApi() {
$arguments = [
'method' => 'GET',
];
$request = wp_remote_get( 'https://example.com.br/api/endpoint/product-id', $arguments );
if (is_wp_error($request)) {
$error_message = $request->get_error_message();
echo "Error {$error_message}";
}
$body = wp_remote_retrieve_body( $request );
$values = json_decode( $body );
return $values;
}