<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: lokesh sunhare</title>
    <description>The latest articles on DEV Community by lokesh sunhare (@lokesh_sunhare_cd0ac18643).</description>
    <link>https://dev.to/lokesh_sunhare_cd0ac18643</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2260028%2Fff955783-3993-41f5-98ce-2e76ec5d7442.jpg</url>
      <title>DEV Community: lokesh sunhare</title>
      <link>https://dev.to/lokesh_sunhare_cd0ac18643</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lokesh_sunhare_cd0ac18643"/>
    <language>en</language>
    <item>
      <title>Make Your Next.js App Fly: Performance Hacks That Work</title>
      <dc:creator>lokesh sunhare</dc:creator>
      <pubDate>Fri, 27 Jun 2025 06:41:47 +0000</pubDate>
      <link>https://dev.to/lokesh_sunhare_cd0ac18643/make-your-nextjs-app-fly-performance-hacks-that-work-2bgf</link>
      <guid>https://dev.to/lokesh_sunhare_cd0ac18643/make-your-nextjs-app-fly-performance-hacks-that-work-2bgf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;There were times when the site felt painfully slow and completely unresponsive moments that left me frustrated and tempted to just give up that's why the Performance optimization is a critical aspect of developing web applications. Users expect applications to load quickly and respond to their interactions smoothly. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When a site takes over 1 second to become interactive, users often lose focus, and their experience feels interrupted.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No lengthy talk here’s the result that speaks for itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvbmkjcairc20vl8nz6p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvbmkjcairc20vl8nz6p.png" alt="Imag-1" width="736" height="626"&gt;&lt;/a&gt;&lt;br&gt;
Back then, performance rate was crawling at 47&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87e6jvp4odmqfbeamvc2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87e6jvp4odmqfbeamvc2.png" alt="Image-2" width="800" height="687"&gt;&lt;/a&gt;&lt;br&gt;
Voila 🎉 near-perfect 96 in performance.&lt;/p&gt;

&lt;p&gt;Want to check your site’s performance? Just head over to Google’s performance tool &lt;a href="//pagespeed.web.dev"&gt;pagespeed.web.dev&lt;/a&gt; drop site URL, and hit Analyze. You can also use Chrome DevTools open Inspect, navigate to the Lighthouse tab, choose your desired device, mode, and categories, then click Analyze page state to see how your site stacks up.&lt;/p&gt;

&lt;p&gt;Optimizing performance in the React ecosystem especially when using frameworks like Next.js, offers many tools to improve mobile and web performance, which is key to delivering fast, responsive applications that keep users engaged and satisfied.&lt;/p&gt;

&lt;h2&gt;
  
  
  First need to understand the Core Web Vitals. The Foundation of Web Performance.
&lt;/h2&gt;

&lt;p&gt;Core Web Vitals are a set of metrics defined by Google to measure the quality of a user's experience on a website. These metrics focus on three key aspects: loading, interactivity, and visual stability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Few Core Web Vitals
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;First Contentful Paint (FCP)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;What it measures: Loading performance (time to render the largest visible element)&lt;/li&gt;
&lt;li&gt;Good threshold: Less than 2.5 seconds&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Largest Contentful Paint (LCP)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;What it measured: Time from first user interaction to browser response&lt;/li&gt;
&lt;li&gt;Good threshold:  Less than 2.5 seconds&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cumulative Layout Shift (CLS)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;What it measures: Visual stability (unexpected layout shifts)&lt;/li&gt;
&lt;li&gt;Good threshold: Less than 0.1 seconds&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Total Blocking Time (TBT)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;What it measured: Total amount of time a webpage is blocked from responding&lt;/li&gt;
&lt;li&gt;Good threshold:  Less than 200 milliseconds&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the Diagnostics, Inspect each section individually and focus on improving the essentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffa5qzp1ztsi9vrpcbiem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffa5qzp1ztsi9vrpcbiem.png" alt="vitals" width="800" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;let's break down the techniques for optimizing the performance of our React/Next.js application.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Optimize the CSS&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;In this project, there were some CSS files used in a few components, each containing around 4,500 lines of code. We removed unused styles, optimized, and minified the CSS, reducing the total lines by 50%.&lt;/li&gt;
&lt;li&gt;Since CSS is render-blocking, it loads before the page is rendered, which can negatively impact performance if not optimized. This improves the &lt;strong&gt;FCP&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; to Prefetch and preload  &lt;code&gt;&amp;lt;link rel="preload"&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;link rel="prefetch"&amp;gt;&lt;/code&gt;   this really helps to improve my performance.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="preload" as="image" href="/herobg.webp" fetchPriority="high" /&amp;gt;

&amp;lt;link
  rel="preload"
  href="/styles/globals.css"
  as="style"
  onLoad="this.onload=null;this.rel='stylesheet'"
/&amp;gt;
&amp;lt;noscript&amp;gt;
  &amp;lt;link rel="stylesheet" href="/styles/globals.css" /&amp;gt;
&amp;lt;/noscript&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reduce JavaScript Bundle Size&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Mobile devices struggle with parsing and executing large JS bundles. This improves the &lt;strong&gt;LCP&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Use dynamic imports with SSR disabled for non-critical components.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Reduce Initial Load&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Lazy-load non-critical components.&lt;/li&gt;
&lt;li&gt;Use dynamic imports &lt;code&gt;(next/dynamic)&lt;/code&gt; or load below-the-fold sections conditionally.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const NonCriticalComponent = dynamic(() =&amp;gt; import('../components/NonCriticalComponent'), {
  ssr: false,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Optimize Images&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Mobile devices have smaller screens and limited bandwidth.&lt;/li&gt;
&lt;li&gt;Use Next.js &lt;code&gt;next/image&lt;/code&gt; which automatically serves optimized images.&lt;/li&gt;
&lt;li&gt;Also, prefetch the image in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag with &lt;code&gt;fetchPriority = "high"&lt;/code&gt;  to reduce initial rendering time.&lt;/li&gt;
&lt;li&gt;Serve WebP or AVIF formats for better compression, avoid heavy images.&lt;/li&gt;
&lt;li&gt;Set proper image sizes via sizes attribute for responsive behavior.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;Image
  src="/herobg.webp"
  alt="hero-bg"
  fill
  priority  // to load on priority 
  sizes="100vw"
  className="object-cover"
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Optimize Fonts&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;font-display: swap, preload: true&lt;/code&gt; to prevent blocking rendering.&lt;/li&gt;
&lt;li&gt;Prefer system fonts or serve self-hosted fonts with proper subsets.&lt;/li&gt;
&lt;li&gt;Initially, our project used multiple fonts like Helvetica and Inter. To optimize performance, We minimized font usage and switched to using only Poppins.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Poppins} from 'next/font/google';
const poppins = Poppins({ subsets: ['latin'], display: 'swap', preload: true, });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Leverage &lt;code&gt;next/script&lt;/code&gt; for control&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Lazy load scripts in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag to improve initial rendering performance.&lt;/li&gt;
&lt;li&gt;Using attributes like &lt;code&gt;async&lt;/code&gt; or &lt;code&gt;defer&lt;/code&gt; for non-critical scripts in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; ensures they don’t block the DOM rendering process.&lt;/li&gt;
&lt;li&gt;To optimize script loading, import also add the strategy to "lazyOnload"
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Script src="https://example.com/script.js" strategy="lazyOnload" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Memoizationl&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;In our project there is few components dealing with computationally intensive or frequently called functions with the same input values, as it helps avoid redundant calculations and improves the overall efficiency of the application.&lt;/li&gt;
&lt;li&gt;memoization: &lt;code&gt;React.memo()&lt;/code&gt;, &lt;code&gt;useMemo()&lt;/code&gt;, and &lt;code&gt;useCallback()&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const memoizedValue = useMemo(() =&amp;gt; expensiveComputation(count), [count]);
const memoizedIncrement = useCallback(requiredFunction, [count]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code Splitting&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Code splitting in React is a powerful technique that breaks down large components into smaller, reusable pieces helping to reduce code redundancy and avoid duplication for better performance and maintainability.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;There are countless ways to boost performance in a Next.js app, but these are the techniques I personally implemented and they made a measurable impact on improving web vitals and overall user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I’ve implemented all the above techniques in my own Next.js project and honestly, it wasn’t all smooth sailing. There were moments of frustration, especially when I applied the wrong optimizations or misunderstood how certain features worked. But through trial and error, learning from performance bottlenecks, and diving deeper into how React really works under the hood, we started to see real improvements.&lt;/p&gt;

&lt;p&gt;What I’ve shared above isn’t just theory these are practical, concise strategies that helped me boost performance in a meaningful way. If you’re going through a similar journey, I hope these insights save you some time (and debugging headaches).&lt;/p&gt;

&lt;p&gt;So that’s it, folks! I’d love to hear your thoughts or experiences with performance optimization techniques.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>performance</category>
      <category>nextjs</category>
      <category>react</category>
    </item>
  </channel>
</rss>
