YouTube is by far the most popular video streaming platform on the internet. Acquired by Google for $1.65 billion in 2006, the platform today has nearly a billion videos uploaded.
A speed report from Lighthouse paints a rather grim picture and scores the YouTube website 7.3 seconds on the speed index (SI), and 33 on Performance.
There are many reasons why the YouTube website is so slow. This includes:
- Unused CSS files
- Unnecessarily large image files
- Render-blocking resources
- Slow server
- Large DOM size
- Ineffective Caching Policy
- Largest Contentful Paint Not Preloaded
Let’s look at each of these reasons and identify potential ways that YouTube can make its website load faster.
But before we do that, a quick word about our website CWVIQ.com - we are a free email alert service that sends out notification any time your website is loading very slowly (often due to heavy traffic, or poor scripts). If you have a website, consider setting up an alert so that you can fix issues before they become major.
The YouTube website can be as much as 2.1 seconds faster by adopting this technique.
Unused CSS files
YouTube uses CSS files to load the styling elements for the website. However, this file contains a lot of unused scripts that can be slowing down page loading by as much as 0.81 seconds. Code splitting may help avoid this issue.
Unnecessarily large image files
Another common problem that users face – especially when they access the website while on the move – is having to load unnecessarily large image files that are not optimized for the mobile phone. Not everyone has access to WiFi at all times. Loading oversized product images is unnecessary.
According to the Lighthouse estimate, the YouTube website homepage can load 0.15 seconds faster if it made all the images more cellular-data-friendly.
There are scripts on the YouTube website that need to run first before they let the rest of the code be executed. The render-blocking resources issue can shave off around 0.65 seconds from the loading time for the YouTube website.
How do you avoid this? If the script is not critical, avoid having it in the <head> tag of your HTML code. But if you do need to have it there for some reason, make sure to include the defer or async attribute so that they do not block the loading of other resources.
According to the Lighthouse report, a slow server may be contributing to nearly 0.54 seconds of additional loading time. In addition to upgrading the server hardware and database systems, YouTube should also look into the server’s application logic to prepare pages faster.
Large DOM size
The YouTube website takes close to 6.8 seconds to evaluate all the scripts, parse them, compile, and render them. This can be minimized by minimizing the main-thread work.
They may also look at reducing the number of nodes in the DOM. In simpler terms, you need to make sure that the main HTML code is smaller and has fewer nodes. I have explained this in greater detail in this article about DOMContentLoaded.
Ineffective Caching Policy
A website like YouTube is made of several components, including a lot of images, and other media files. Caching, or storing these components in your local computer, enables your browser to load the website much faster when you come back a second or third time.
With YouTube, however, the cache for most media files clear is deleted every 5 minutes. This means that the website is loaded completely from scratch any time you visit after 5 minutes. Enabling a longer cache period could make loading pages faster and more user-friendly.
Largest Contentful Paint Not Preloaded
Largest Contentful Paint (LCP) refers to the time it takes for the page’s main content to be completely loaded. Loading the LCP using a preload scanner ensures that the entire content is available for the user to view at the earliest. However, YouTube does not preload this content, and this causes a 1.83 seconds delay in the page-loading process.
Anand Srinivasan is the founder of CWVIQ, and has been in the internet media space for over 15 years. He has previously served as the AVP of Products and Head of Business at popular media portals. He has worked with several SaaS and enterprise businesses as an external consultant for their SEO marketing campaigns.