Directory of RSS feeds
Statistics

RSS feeds in the directory: 2819

Added today: 0

Added yesterday: 0

Hi-Tech / Other

The embeddable random videos from Youtube on the website

Typical Internet guy ™ 25.09.2018 at 20:15

Vyacheslav Scoble: about creativity, about life and other nonsense, giving advice: how to live on the Internet, how to survive and what to do with all this

Video animates Your website, improve behavioral factors. But one thing, when the video illustrates the article and it is quite another thing if You want to make the video widget to embed the template of your site. In the latter case, behavioral factors (PF) on the contrary will worsen. The fact that to see the splash screen of the same video while moving around the website the user will be unpleasant to contemplate. What to do? Correctly implement the ability to display the videos randomly (random).

option 1 in PHP

you Can make an array of ready video codes Youtube, put them in a plain text file (each code on a separate line) example:

...

And retrieve this array of random line by posting on its website (in the widget/sidebar) like this PHP code:

This code is implemented in the footsteps of the article "Create a widget with random data".

it would be good, but such unfriendly code with static caching, which I love to include webmasters in the pursuit of high performance "PageSpeed Insights". If the site has a cache, then this widget will not work for dynamic (updating page in the browser will not generate a random video)!

Method 2 using JavaScript

JavaScript works on the client side, i.e. in the user's browser. This means that no cache of the site it is not terrible. This is the perfect scenario for writing dynamic informer - random video.

this code Consists of 3 parts:

an Array of video files (the format is video id from Youtube); Functions for getting random numbers; Rendering the iframe (the full code of the Youtube player);

In practice, it looks like the following:

This code displays in the user's browser random video (of the proposed array) from Youtube. The seamless attribute in an iframe means that the content of the frame will appear as if it is part of the document. And set the width to width=1280 means that the video carefully fill the allotted area of the screen.