Reputation: 35
I created a webpage a while ago with php(+ a webAPI) and I want to rewrite it to javascript now.
The problem:
The site loads a lot of data and needs about 5-7 sec to fully load, which is not optimal. I want to use javascript to 'build' the side part by part. With php (after clicking 'load') nothing (for the user visible) happens for 5-7 secs and the browser creates the whole page at once. I want the user to see how the page is built, like first block first, then second block, not the whole page at once.
I've read that this should be possible with javascript and now I want to rewrite the page.
I'm currently using php to get the information like this:
$feedraw = file_get_contents('https://' . $region . '.api.battle.net/wow/character/' . $server . '/' . $charname . '?fields=feed&locale=en_GB&apikey=' . $api_key . ');
$feedarray = json_decode($feedraw);
After feeding my $feedarray with data, I access the data via (example)
foreach ($feedarray as $feed) {
if ($feed->type === "ACHIEVEMENT") {
echo $feed->title;
}
}
Or is it even possible to load the site partially with php?
Thanks in advance
Upvotes: -1
Views: 44
Reputation: 13707
The answer to your question is basically “yes, learn JavaScript”.
However, I would possibly suggest that if you want to stick to your existing site, maybe consider saving the requests so that each time the page loads, it doesn’t have to fetch them all. Then using a cron job to fetch the pages every hour (or something) in the background.
See something like: Simple PHP caching
Upvotes: 0