I’ve got a very slow performing page, because it’s loaded down by JSON requests.
So I was wondering how I can speed the whole thing up. Can I request only part of the string? Considering all I’m using from the following one is the “cast” array, it’s a waste to have to get all of it.
The following code has to run for every movie listed on my page, which at the moment is 20. But before just cutting the number of movies down, I was wondering how I could speed this part up, which is the proper problem.
Here’s the code I’ve got that slows the page down, as it has to run 20 times.
$films_result = $tmdb->getMovie($film->id);
$films = json_decode($films_result);
foreach ($films as $film) {
foreach ($film->cast as $cast) {
if ($cast->job == 'Actor') {
echo '<a href="person.php?id=' . $cast->id . '">' . $cast->name . '</a> ';
$num_actors++;
if ($num_actors == 5)
break;
}
}
}
I’ve had a look around, but I don’t know what I’m looking for. I’m very very much a beginner at this. So please could any solutions not involve any other technologies, just PHP please.
Your API gets 0 of 100 points in google page speed because the compression is disabled.
Your JSON output will load 95% faster with compression enabled.
It might be hard to fix if you are not in control of the server but here’s a link how to fix it anyways.
Minimize payload