Lag, where is the problem?

i put this script but my web site now run with lag…

$stream_name = ‘twitch.tv’; /Stream name /
$orginal_width = 400; /
Orginale Breite vom Playereinbindung /
$orginal_height = 300; /
Orginale Höhe vom Playereinbindung /
$width = get_streamwidth();
$height = ($width
100)/$orginal_width;
$height = ($height
$orginal_height)/100;
$live = false;
$views_stream = 0;
$embed = ‘’;

	if(!$height OR !$width) { $width = $orginal_width; $height = $orginal_height; }
	
		if(isset($id)) {
				$file = 'https://api.twitch.tv/kraken/streams/'.$id;
				$twitch_json = json_decode(@file_get_contents($file));
				if ($twitch_json && $twitch_json->stream) {
				$live_stream = 1;
                $views_stream = $twitch_json->stream->viewers;
                $embed = '<object type="application/x-shockwave-flash" height="'.$height.'" width="'.$width.'" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel='.$id.'" bgcolor="#000000"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" /><param name="flashvars" value="start_volume=25&hostname=www.twitch.tv&channel='.$id.'&auto_play=true" /></object>';
                }
		}

someone can help me?

Hey CusturA,

I’ve noticed you’re using an object element. I’ve found to embed a Twitch stream works best using an iframe element. It’ll cut down on your code substantially.

If you go to any Twitch stream, and share the stream you will find there a link to embed the stream using an iframe element. I suggest using that as a template and replace any attributes to preference.

Give it a shot and see if the lag goes away!

Kakeiso

1 Like

i put, but again lag…

If by “lag” you mean the page loads slower, this is because you are fetching a remote resource on every page load. Use JavaScript instead to load APIs client-side.

how i can put this javascript for use without lag

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.