How to speed up a slow React website

A slow React site is sending too much JavaScript. What to fix first, and why useMemo comes last.

Mohit Goyal9 min read
How to speed up a slow React website

The browser has to download and run a React site's JavaScript before it can show the page, and a slow React site is sending too much of it. So most of the work is sending less script and getting real HTML into the first response. useMemo and React.memo, the tricks people reach for first, come last, because they do very little for load time.

The fixes, in the order to do them:

FixWhat you get
Measure with PageSpeed Insights and a bundle analyserNo speed gain, but you stop guessing
Remove or replace heavy librariesLess script to download and run
Import by name, one icon setA smaller bundle with no visible change
Split code by route, lazy-load below the foldThe first page loads only what it needs
Server render or prerenderContent shows before scripts load. The largest LCP change for apps that render only in the browser
Responsive images, hero not lazy, sizes setFaster LCP, less layout jump
Preload fontsText appears sooner
Cut or delay third-party tagsLess blocking time on mobile
Fix re-renders, virtualise long listsSmoother typing and clicking. Little change to load time

Stop when the numbers pass. I build React and Next.js sites for a living, and I did this clean-up on my own site, mohitgoyal.in, which runs on React 19 and TanStack Start.

How do I find out what's making my React site slow?

Run the page through PageSpeed Insights on mobile, then open a bundle analyser. Those two reports tell you where the time goes before anyone touches the code.

PageSpeed Insights gives you two kinds of numbers. The top part is field data from real Chrome users, if your site has enough traffic. The lower part is a Lighthouse lab test. A visitor on a budget Android phone on mobile data has a far slower device and connection than your MacBook on office Wi-Fi, so don't wave the mobile score away because the site feels fine at your desk.

Google's targets, from web.dev's Core Web Vitals page, are:

MetricWhat it measuresGood
LCP (Largest Contentful Paint)How long the main image or heading takes to appearWithin 2.5 seconds
INP (Interaction to Next Paint)How long the page takes to react to a tap or click200 milliseconds or less
CLS (Cumulative Layout Shift)How much the page jumps around while loading0.1 or less

web.dev says to measure these at the 75th percentile of page loads, separately for mobile and desktop. That means three out of four visits should hit the target.

The Lighthouse score points the same way. Chrome's Lighthouse scoring page gives Total Blocking Time 30% of the performance score and LCP 25%. Total Blocking Time is the time the browser is stuck running scripts and can't respond. So 55% of the score is tied to how much JavaScript you send and how soon the main content shows.

The score also changes from one run to the next, and people end up arguing about which run is right. Chrome's page says to think of it as a spread of scores, not a single number. Run the test three times and look at the metrics, not the badge.

The bundle analyser is the second report. A bundle is the JavaScript file your build tool produces, and the analyser draws it as a map of boxes, one per library, sized by weight. On Next.js that's @next/bundle-analyzer. On Vite it's rollup-plugin-visualizer. Ask your developer for a screenshot. You don't have to read code to spot one library taking a third of the picture.

Send less JavaScript

Heavy libraries

Open the analyser map and question the biggest boxes. The usual ones are an animation library, an icon pack, a date library, a charting library, and a rich text editor that only the admin screen uses.

On mohitgoyal.in, an animation library and an icon library came out of most pages. Parts of the site tilt when you hover, and the buttons pull slightly towards the cursor. Both effects used to come from the animation library. They now use CSS transforms driven by a few lines of script, with no animation library. The scroll animations were split into small components that load only on the pages that use them.

If a library exists on your site to make one button wiggle, delete it. A visitor on a Redmi phone gets a page that opens sooner, and nobody misses the library.

Imports

Tree shaking is the build step that drops code you never call. It only works if the code is imported by name. This is the difference, for your developer:

js
// Pulls in the whole library
import _ from "lodash";

// Pulls in one function
import debounce from "lodash/debounce";

Icons are the common trap. A project picks up a second and a third icon pack over the years, each added for a handful of icons. Settle on one icon set that tree-shakes, so only the icons on the page end up in the bundle.

Code splitting

Code splitting means the browser downloads the code for the page it's on, not for the whole site. Frameworks like Next.js and TanStack Start split by route for you. A plain React app made with Vite or the old Create React App does not, unless your developer sets it up.

For things below the fold (the part of the page you have to scroll to see), React has lazy. The React docs for lazy say React won't load the component's code until the first time you try to render it. Good candidates are maps, video players, chat windows, carousels and anything inside a popup. Have the developer give the placeholder a fixed height. If it has none, the page jumps when the real component arrives and your CLS gets worse.

Should a React site be server rendered?

A classic React app sends a nearly empty page and a big script, and the script builds the page in the browser. On a slow phone that's a white screen for seconds, and your LCP can't be good no matter what else you tune. It also hurts search, which I covered in my post on why a React website isn't ranking on Google.

Server rendering turns that around. The server sends finished HTML, so the visitor sees content before the JavaScript has loaded. For a public site that needs to load fast and rank, do it.

Prerendering is the cheaper version of the same idea. Pages are built into HTML once, at deploy time. For a marketing site, a blog or a catalogue that changes a few times a day, prerender. For pages that differ per visitor, server render.

This is the biggest single change in the table and also the most work, because it means moving to Next.js, TanStack Start or a similar framework. If the analyser shows a five-year-old Create React App build with libraries nobody remembers adding, a rebuild on one of those frameworks can be cheaper than patching. And if you're already on Next.js and still failing, the problem is elsewhere. My Next.js Core Web Vitals fix post walks through that case.

Images and fonts

On a marketing page the LCP element tends to be the hero image, so this is what moves LCP once the JavaScript is under control.

Serve each image at the size it's shown. mohitgoyal.in serves responsive image sizes, which means a phone gets a small file and a desktop gets a bigger one. It also preloads the two fonts the page uses, so text doesn't wait in a queue behind other files. Then check that the hero image is not lazy-loaded, that every image has a width and height set so the layout doesn't jump, and that images below the fold are lazy-loaded.

Formats and compression are in how to optimise website images without losing quality.

Tracking tags and chat widgets

Count them. Google Tag Manager, GA4, Meta Pixel, a heatmap tool, a WhatsApp chat bubble, a popup tool, and a payment script such as Razorpay's loaded on every page when only checkout needs it. Each tag is someone else's JavaScript running on your visitor's phone, and on marketing sites the tags are sometimes heavier than the site's own code.

Remove the ones nobody looks at. Load the chat bubble after the visitor scrolls or after a few seconds. Load payment scripts only on the pages that take payment.

The tags belong to marketing and the score belongs to the developer, so nobody owns the problem. Somebody has to. The Tag Manager side has its own post: is Google Tag Manager slowing down your website.

Re-renders, useMemo and React.memo

These make a loaded page respond faster, which helps INP. They do nothing for how long the page takes to appear, so a "React optimisation" quote that starts with memoisation on a site that's failing LCP has the order backwards.

A re-render is React redrawing part of the page. Memoisation is React remembering a result so it can skip that work. If typing in a search box or opening a filter feels sticky, look here. Use the Profiler in React DevTools to see which components redraw on each keystroke. And if you show a list of thousands of rows, use list virtualisation (a library such as TanStack Virtual or react-window), which draws only the rows on screen.

Before your developer hand-writes useMemo everywhere, look at React Compiler. The React Compiler docs describe it as a build-time tool that memoises components automatically, and say it is now stable. The same page says to leave existing manual memoisation in place, so it's not a reason to rip things out of old code.

For an app that lives behind a login, this section moves to the front. A dashboard or an internal tool that staff open once in the morning and use all day doesn't need server rendering or a perfect LCP. Its slow moments are re-renders, long lists and filters, so start there.

Frequently asked

How do I speed up React JS load time?+

To speed up React load time, cut the JavaScript the page sends: remove heavy libraries, import only the functions you use, and split the code by route. Then server render or prerender the page so the visitor gets real HTML before the scripts finish loading.

Why is my React website slow on mobile but fine on my laptop?+

A React website builds the page with JavaScript, and a budget phone on mobile data downloads and runs that JavaScript far more slowly than a laptop on Wi-Fi. That gap is why a React website's mobile result in PageSpeed Insights is lower than its desktop result.

Does useMemo make a React site load faster?+

No. useMemo and React.memo stop React from redoing work after the page has loaded, so they help with slow typing, filtering and clicking. They don't reduce the amount of JavaScript the browser has to download, so load time stays the same.

Do I have to move to Next.js to fix React performance?+

Not always. If the React site is a public marketing site or store that renders only in the browser, moving to a framework that server renders, such as Next.js or TanStack Start, is the biggest fix for LCP. A dashboard behind a login doesn't need that move and gains more from fixing re-renders and long lists.

Mohit Goyal

Written by Mohit Goyal

Senior Web Developer in Gurugram, India. 100+ fast, SEO-friendly sites shipped in 4.5+ years with Next.js, React and WordPress, including the procol.ai rebuild. Send me your next project.

I work as a freelance web developer in Gurugram, India.

Keep reading

Website speed optimisation services: what gets fixed and what it costs

What website speed optimisation services fix on WordPress, React and Next.js sites, what they cost, how long they take and what to ask first.

22 min read

Hire a freelance React developer: rates and what to check

What a freelance React developer charges in the US, UK and India, where to hire one, and the checks to run before you pay a deposit.

16 min read