Omid Sayfun
Omid SayfunComputer Geek
Home
Notebook
Journey

Online

Github
Linkedin
Read.cv
Notebook
A try at type-safe groupBy function in TypeScript
April 10, 2025
Adding prettier to eslint
April 10, 2025
Upgrading my blog to Next 15
April 05, 2025
tsx doesn’t support decorators
March 26, 2025
Extending Window: types vs interfaces
March 21, 2025
Loading env file into Node process
February 06, 2025
Validating NestJS env vars with zod
February 06, 2025
Using node API for delay
February 06, 2025
React Component Lifecycle
November 28, 2024
Email special headers
November 20, 2024
How CQRS is different than Event Sourcing
August 18, 2024
RabbitMQ exchange vs queue
August 14, 2024
PgVector similarity search distance functions
August 13, 2024
PgVector indexing options for vector similarity search
July 31, 2024
Counting GPT tokens
June 30, 2024
Logging route handler responses in Next.js 14
June 19, 2024
Redirect www subdomain with Cloudflare
June 17, 2024
Logging requests in Express app
June 16, 2024
Move Docker volume to bind mount
June 12, 2024
Using puppeteer executable for GSTS
June 08, 2024
Next.js Hydration Window Issue
May 29, 2024
Using Git rebase without creating chaos in your repo
May 16, 2024
Why EQ is Your Next Career Upgrade
May 13, 2024
Storing Vector in Postgres with Drizzle ORM
March 21, 2024
Implementing RPC Calls with RabbitMQ in TypeScript
March 16, 2024
Optimize webpage load with special tags
March 15, 2024
What the hell is Open Graph?
March 13, 2024
My go-to Next.js ESlint config
March 10, 2024
List of useful Chrome args
March 10, 2024
Add update date field to Postgres
February 27, 2024
Combining RxJS observables - Part 1
February 20, 2024
Canvas macOS issue
February 20, 2024

Optimize webpage load with special tags

March 15, 2024

In today's fast-paced web, website speed is crucial. Even a slight delay can cause visitors to bounce, hurting conversion rates and SEO. I’ll dive into four key techniques to optimize website loading: preload, preconnect, prefetch, and DNS prefetch.

Talking to the browser

These techniques are all about giving the browser hints on what resources it will likely need for your website. By anticipating these needs, the browser can start fetching resources before they're explicitly requested, leading to a smoother user experience.

Preload

Use preload for critical resources that are essential for the initial rendering of your page. This could include fonts, critical CSS files, or above-the-fold images. Preloaded resources are fetched with high priority, ensuring they're available when needed.

<link rel="preload" href="font.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="critical.css" as="style">

Prefetch

Prefetching is best for resources that are likely to be needed on subsequent page visits or user interactions. For example, you might prefetch resources for a product page that a user might visit after viewing a category page.

<link rel="prefetch" href="/product/[id]">

Preconnect

Preconnect establishes a connection to a specific server early on, allowing resources from that server to be downloaded faster. This is useful for resources hosted on a CDN or third-party services.

<link rel="preconnect" href="https://cdn.omiid.me">

DNS Prefetch

DNS prefetch focuses on a single step in the resource loading process: Domain Name System (DNS) lookup. By prefetching a DNS record, the browser can resolve the domain name to an IP address before it's needed, saving a roundtrip to the DNS server.

<link rel="dns-prefetch" href="https://fonts.googleapis.com">

Quick Overview

TechniqueProsCons
PreloadImproves initial page load time for critical resourcesCan slow down page load if too many resources are preloaded
PrefetchImproves perceived performance for subsequent page visitsDoesn't guarantee resources will be fetched
PreconnectReduces latency for resources from specific domainsCan increase initial page load time slightly
DNS PrefetchMinor improvement in initial page load timeBenefit might be negligible for some browsers

Noteworthy

  • Prioritize Critically: Focus on preloading critical resources that directly impact your initial page load. Don't overload the browser with too many preloaded resources.
  • Consider User Behavior: Use prefetch strategically to anticipate user actions and prepare resources for subsequent pages.
  • Test and Monitor: Always test the impact of these techniques on your website's performance. Use browser developer tools (I mostly use PageSpeed Insights) to monitor resource loading times and identify bottlenecks.

Continue Reading

  • 13-03-2024

    What the hell is Open Graph?

  • 30-05-2024

    Next.js Hydration Window Issue

  • 29-11-2024

    React Component Lifecycle

  • 10-03-2024

    List of useful Chrome args

  • 10-04-2025

    Email special headers