Modern websites are composed of HTML, dynamic JavaScript elements, images, video, and other rich media. On most websites, rich media accounts for most of page load time and are the heaviest elements the user needs to retrieve over their limited bandwidth.
Videos on the web are a double edged sword. On the one hand, they can make a website much more compelling and engaging for users. On the other hand, they can create usability issues, performance problems and security concerns.
In this article I’ll explain several ways to optimize videos, to ensure they contribute to the user experience, without harming it. I’ll cover how to select the right video format for your website and web application, and several tips to improve usability and performance for video content.
Video optimization starts with selecting the right format. There are many video formats out there, but many are not suitable for use on the web, due to performance issues, user experience, or security concerns.
Let’s review a few modern formats that are suitable for websites, and understand their pros, cons, and technical properties. Here are the main video formats you should consider using in your website or web application.
Progressive video file formats:
Adaptive bitrate (ABR) file formats:
Note that the following tips are useful if you are hosting your own video and streaming it directly from your web server. If you opt to host your video on an online video platform (OVP) such as YouTube or Vimeo, the platform will take care of most of these issues.
Make Videos Usable
The most important thing to remember when optimizing online video is to provide users with a good experience. Here are a few key points to consider for improving user engagement:
Deliver Video Using HTML5
Today it is extremely common to deliver videos over HTML5, which allows you to serve video content to your website visitors without requiring a plugin. You’ll need to use an HTML5-supported format.
MP4 files are the most popular and are supported by all browsers, while Chrome, Firefox and Opera also support other formats such as WebM and Ogg.
Here is how to embed an HTML5 video into a web page, providing two versions of the file, WebM and MP4:
<video controls>
<source src="{FILENAME}.webm" type="video /webm">
<source src="{FILENAME}.mp4" type="video /mp4">
Sorry, your browser does not support video content.
</video >
Here are attributes you can use as part of the <video> tag to control the video experience:
controls
- defines whether play/pause button and volume slider are displayed to the userautoplay
- if set to true, the video will start playing as soon as enough of it is bufferedposter
- preview image for the videoYou can also use HTML5-enabled video players like Video.js or the Cloudinary video player.
Use CDN
You can use a content delivery network (CDN) to stream video content and make it instantly available to users. Users don't have to wait for the video to be downloaded and buffered. CDNs are built into OVPs, but you can also use a CDN for videos you stream directly from your servers.
CDN uses a variety of caching techniques to ensure fast delivery of media. Popular video content is cached, and can then be quickly accessed by other users in the same location. The infrastructure and geographic coverage provided by the CDN allows users to access video from any device and location, without affecting video quality or web page performance.
Optimize Streaming Startup
When streaming video, a best practice is to start with the lowest quality stream to get the fastest playback speed. For long videos, it is recommended to use a medium quality stream at the start to deliver a sharper result and avoid disappointing viewers.
When requesting a video stream, the server provides a manifest file so that the player can list all available streams (including size and bitrate information). In HLS streaming, the player usually starts playing by selecting the first stream in the list.
You can leverage this by optimizing the first stream placed in the manifest file, making sure it runs optimally for the relevant device. You should provide alternative manifest files for mobile and desktop devices.
You can allow users to start streaming faster by providing a low quality stream as the first stream in the manifest. Later on, as the client-side player better understands the available throughput, it will download additional clips and can upgrade to a higher-quality stream. This means the user will initially see the video with some pixelation, and then it will become sharper. This can prevent a delay of 5-20 seconds that can happen in many streaming scenarios.
In this article I covered a few video formats that can provide a good experience for websites and web applications, including progressive formats like H264/AVC, H265/HEVC, and bitrate streaming protocols like HLS and MPEG-DASH.
In addition, I provided a few tips and tricks for improving performance and user experience for videos on your site:
I hope this will help you improve the delivery of rich media files to your users, improve page load time and create a better user experience.