Speeding Up Tesla.com (4 Part Series)
I like Tesla. I think they are a great company, working towards a better future. That's why I was on their website recently, on a pretty average connection, and I noticed that it is loading very slowly. So of course, me being me, I opened Firefox dev tools and started digging around.
TLDR: At the end of the day I managed to speed up homepage time to interactive from over 17 seconds to around 4 seconds by removing unnecessary things and optimizing assets delivery.
This two-part article series is meant to show a real-world use case of how you can:
- Notice problems - Run webpagetest / Lighthouse on your website
- Identify rooms for improvement - Look for heavy resources, number of requests and pay special attention to CSS because it's blocking
- Remove what's not needed
- Split into smaller chunks what is needed
- Lazy load what is not critical
- Load on demand what is not used by at least half of the users
Those are the easiest techniques, that don't involve rewriting the code or changing any functionality of the page, which is what this audit/article is supposed to demonstrate.
After running webpagetest and Lighthouse on the site, I identified the following problems:
- The main photo is in PNG format (7.7 MB)
- Non minified Boomerang.js library (http://www.boomerangjs.org/)
- Some fonts are inlined inside CSS but never used
- Some fonts are inlined, but really should not be
- Most inlined assets are duplicated (huge savings can be achieved there)
- Some assets for all 44 languages are included in the main CSS file, even though a user can use only one at a time
- A lot of media queries, which at this size should be separated into multiple CSS files
- Main JS file is heavy and it looks like it could be divided into smaller parts and lazy loaded
I did the following to speed up the site:
- Compress image and use JPEG format - saved 6.7 MB + improved perceived performance by using progressive JPEG
- Remove unused font - made the page lighter by 150 KB, and because it was inside CSS, it is no longer blocking rendering
- Minify the boomerang.js library - 120 KB → 40 KB
In webpagetest, the most significant thing is Largest Contentful Paint. This means that this 7 MB hero image was loaded after 16 seconds.
Let's address the first issue first because it is the lowest hanging fruit of the bunch and does not require any technical knowledge. As I wrote in my article Optimizing Images for the Web you can basically tell which format should be used for an image by the contents of it. In this case, it should be JPEG and I'm going to use MacOS Preview to save it as a JPEG and then compress it using ImageOptim.
To make sure that I'm not going to degrade the quality of the image (it is a product page, so it has to look good) I used quality >90, which produces minimal artifacts. Results are pretty good, saving over 7 MB on that one image. Additionally, JPEG is progressive, so it will load in a much more pleasant way than PNG.
I noticed that the
book-override.font.css file had inlined some Gotham fonts, but never used them. I removed the reference to them from the HTML file altogether.
As a result of those operations, the site got lighter by around 7 MB without any advanced techniques.
Let's see what Lighthouse says about it (after it has been uploaded to platformOS as hosting):
A little bit better. Let's hope the next steps will improve it further.
In part two of this series, we will take a look at the huge (2.5 MB!) CSS file and cut it down to 365 KB.
Since I started writing this article, Tesla.com did exactly what I described here in regards to images, and even used more aggressive compression, so their image is 370 KB, which means there was no need to have it in such a good quality after all. :)
You can see the results and source code here:
Posted on Jun 1 by: