Every millisecond matters when it comes to the web. A sluggish website results in decreased conversions, higher bounce rates, and a bad user experience. But the good news? You donβt need a complete rewrite to see improvements! Here are quick and effective performance hacks to speed up your frontend web apps.
Your app might already be carrying unnecessary weight due to large or outdated libraries. Reducing bundle size is an easy win for performance.
Every package you use adds to your bundle size. Some libraries, while useful, might be too heavy or not optimized for modern bundlers.
π Example: (Minified + Gzipped bundle)
moment.js (73.1kB) β suitable for backend applicationsdate-fns (17.5kB) β lightweight & tree-shakabledayjs (3kB) β moment.js replacement for performanceRun webpack-bundle-analyzer or vite-bundle-visualizer to spot unexpectedly large imports in your project.
Use Bundlephobia (bundlephobia.com) to check the size of a package before installing it.
Tip: Opt-in for ESM-based libraries that support treeshaking to avoid unnecessary code.
Even if you choose lightweight libraries, your built code may still include some unused code.
We can use Tree shaking and code splitting to ensure that browsers only download what's necessary.
Modern JavaScript bundlers e.g. Webpack can eliminate unused codeβbut only if the libraries you use support it.
For Tree shaking try the following:
π Example:
import _ from "lodash";
console.log(_.cloneDeep(obj));import cloneDeep from "lodash/cloneDeep";
console.log(cloneDeep(obj));Instead of loading everything at once, split your code into chunks so the browser loads them only when required and this will save on network loading and browser parsing times.
π Example:
import { lazy, Suspense } from "react";
const HeavyComponent = lazy(() => import("./HeavyComponent"));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<HeavyComponent />
</Suspense>
);
}
Tip: Always use lazy loading for non-essential components to keep your initial load fast.
Slow network requests and unoptimized images cripple web performance. Optimizing these can significantly improve page load speeds hence user experience.
Each request adds latency, so reducing them speeds up page rendering.
Here's what you can do:
<link rel="preload" /> to prioritize important resources such LCP image, fonts, etc.π Example:
<link rel="preload" href="/fonts/roboto.woff2" as="font"
type="font/woff2" crossorigin="anonymous">
<img src="image.webp" width="600" height="400" loading="lazy" alt="Optimized Image">
Tip: Always provide width and height for images to improve CLS and use lazy loading for non-visible assets.
All rights reserved.