so there is a way to get youtube video information via php/javascript. But I am not sure I should use Php or javascript.
Which method will make the page load faster?
Should I host the videos on my websites or put them on youtube and use something like JW player?
Currently, I write the code in PHP. I have a list of video ids from youtube. The php code read all of these ids, loop over them to feed information like video’s titles, descriptions, etc. And display these information on the page. Thank you!
foreach ($vidIds as $vidId){
$xml ="http://gdata.youtube.com/feeds/api/videos/" . $vidId;
$doc = new DOMDocument;
$doc->load($xml);
$ns = "http://search.yahoo.com/mrss/";
$title = $doc->getElementsByTagNameNS($ns, "title")->item(0)->nodeValue;
$desc = $doc->getElementsByTagNameNS($ns, "description")->item(0)->nodeValue;
$thumbnail = $doc->getElementsByTagNameNS($ns, "thumbnail")->item(2)->getAttribute("url");
<div class="preview-frame">
<a href="player.php?vidId=<?= $vidId ?>" >
<img class="preview-img" src="<?= $thumbnail ?>" alt="Te Cong preview image"/>
</a>
<div class="preview">
<span>
<a href="player.php?vidId=<?= $vidId ?>"><?= $title ?></a>
</span>
<br/>
<?= $desc ?>
</div>
</div>
<?php } ?>
Php and Javascript are fine, but if you are constantly grabbing this information from the youtube and yahoo pages you will always have a slow page. If you can setup a cron job to cache the results and then only read from this cache at page load you should greatly speed up your page load times. This is not a language issue it is more of a backend design issue.