BLOG
ARTICLE

5 Simple Tricks to Boost Your Website Performance

5 min read

This time I would like to share a collection of tricks that I'm implementing in my websites to improve their performance.

1. Use Smaller Font File

If you self-host your fonts, try to use modern file extensions woff or woff2 format instead of ttf. ttf (True Type Font) fonts are considered the 'old' type, developed as far as the 1980s. They typically have larger sizes than their counterparts woff (Web Open Font Format), a rather new type developed as recently as 2009 woff.

The size difference is evident here.

Tap to enlarge this image 👇
01.png

There are numerous online converters out there to help you convert ttf to woff/woff2 easily.

2. Avoid Adding Unnecessary Package

Every npm package that you add to your bundle is a cost. That's the undeniable truth. Do you really need that package that you may replace with a few lines of code or that package that you only use once on your page?

One of the popular utility packages for time and date is moment.js. It's handy, yes, but if not used correctly, it may bloat the size of your client bundle. I stopped using it a while ago since I don't really show many dates on my website.

Always think before adding a new package to your code. The default is not to use. But if you have to add, use Bundlephobia to find out how big is the package you want, or if it has a better, slimmer alternative.

3. Defer Not Critical Third-Party Scripts

The easiest example of this is Google Analytics, which is an indispensable tool for all website owners. But it's also blocking the main thread and make Lighthouse complains every single time.

Tap to enlarge this image 👇
02.png

To deal with this, try to load the scripts last in your code. Typically you can put it in the last position before the closing tag of HTML.

In React I do something like:

1
2
3
4
5
6
        {/* Global Site Tag (gtag.js) - Google Analytics */}
        <script
            defer
            src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
        />
    </Html>

This will result in the script being called last:

Tap to enlarge this image 👇
03.png

4. Utilize Code Splitting

Code splitting is the splitting of code into various bundles or components, which can then be loaded on-demand or in parallel. (from Mozilla)

Bundlers like Webpack or Rollup make it easy for us to separate some parts of our website page to load independently beside the main thread. With React it's even easier: dynamic-import.

1
2
3
import("./expensiveComponent").then(component => {
  <>YOUR HEAVY DUTY COMPONENT HERE</>
});

Even much easier in Next.Js:

1
2
3
4
5
6
7
import dynamic from 'next/dynamic';
const DynamicProfile = dynamic(() => import('components/Profile'));
...
return (
    <>
        <DynamicProfile />
    </>

5. Pay Attention to Above & Below the Fold

Ok, this last trick might not be a simple one. This may involve changing your website design and may apply more to mobile users compared to desktop users. But since people use smartphones most of the time, optimizing for mobile is more paramount than desktop.

Let's think of it this way. In mobile, you have minimal space, although screen size depends on the device type. And to make use of that precious space, your browser does not load everything all at once. It loads your website part-by-part.

The part of your website shown on your screen right after page load is called 'Above the fold'. Everything else is not shown immediately, such as the footer or the main content below a beautiful hero image, is called 'Below the fold'. To boost the performance, all you have to do is optimize those visible parts. Simple. Anything else you can load later, it's not important to show in the initial page load.

In my photography website, I purposely made a huge hero section covering the whole screen. Aside from a marketing point of view, I did this to improve the performance. All Google sees for the first time on my home page is hero section, and thus I just need to focus on the optimization of that hero.

This gets me a score of 90 for mobile in Page Speed Insight!

Tap to enlarge this image 👇
04.jpg

Closing

That's it. I hope these tricks are useful.

One trick that I initially wanted to include in the article is optimizing images. But then again, image optimization is a huge and complex topic and not really a 'trick'. Plus, there are already so many great articles out there that delve deep into the matter.

Jerfareza Daviano

Hi, I'm Jerfareza
Daviano 👋🏼

Hi, I'm Jerfareza Daviano 👋🏼

I'm a Full Stack Developer from Indonesia currently based in Japan.

Passionate in software development, I write my thoughts and experiments into this personal blog.