<?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>Forem: Humjerry⚓</title>
    <description>The latest articles on Forem by Humjerry⚓ (@humjerry).</description>
    <link>https://forem.com/humjerry</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%2F872556%2F0dab5a79-b908-421e-bb25-defc97406f25.jpeg</url>
      <title>Forem: Humjerry⚓</title>
      <link>https://forem.com/humjerry</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/humjerry"/>
    <language>en</language>
    <item>
      <title>My First Steps into Cloud-Native: Docker, Minikube &amp; WSL2 Setup</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Thu, 05 Jun 2025 13:08:18 +0000</pubDate>
      <link>https://forem.com/humjerry/my-first-steps-into-cloud-native-docker-minikube-wsl2-setup-3hee</link>
      <guid>https://forem.com/humjerry/my-first-steps-into-cloud-native-docker-minikube-wsl2-setup-3hee</guid>
      <description>&lt;p&gt;I can say my move into cloud-native technologies feels overwhelming at this point.This is because there are a lot of tools, configurations, and concepts to wrap my head around. But with curiosity and consistent effort, things are starting to click. In this article, I’m sharing my hands-on experience transitioning into the cloud-native space, starting with Docker, Minikube, and WSL2. This is my first practical step in my long journey unto DevOps and release engineering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Look at WSL2, Minikube, Docker and Podman
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is WSL2?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://ubuntu.com/desktop/wsl" rel="noopener noreferrer"&gt;WSL2&lt;/a&gt; is short for Windows Subsystem for Linux version 2. It enables to you run a real Linux system inside your Windows PC,  like having two computers in one machine. It is very helpful because many cloud tools are made for Linux, and WSL2 allows to you use them without needing a separate machine or virtual setup. I Like especially as it is very light and convenient.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Minikube?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://minikube.sigs.k8s.io/docs/" rel="noopener noreferrer"&gt;Minikube&lt;/a&gt;, you can see it as a mini version of Kubernetes that runs on your PC. &lt;a href="https://kubernetes.io/" rel="noopener noreferrer"&gt;Kubernetes&lt;/a&gt; been a tool used to manage apps in the cloud, &lt;a href="https://minikube.sigs.k8s.io/docs/" rel="noopener noreferrer"&gt;Minikube&lt;/a&gt; helps you learn and test it without needing a real cloud account. It’s just perfect for beginners who are eager to practice how apps are deployed and managed in the cloud.&lt;/p&gt;

&lt;h3&gt;
  
  
  How is Docker similar to Podman?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; and &lt;a href="https://podman.io/" rel="noopener noreferrer"&gt;Podman&lt;/a&gt; are both tools that help you run apps in containers, which are like small, portable computers for your software. &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; needs a background service to work, while &lt;a href="https://podman.io/" rel="noopener noreferrer"&gt;Podman&lt;/a&gt; doesn’t, it runs more simply and securely. They all do similar things, but Podman is often used when you priotize more control and security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I’m Transitioning to Cloud-Native
&lt;/h2&gt;

&lt;p&gt;For someone like me who is coming from a background in technical support, Linux server administration, and PACS/RIS systems in the healthcare technology industry, I’ve always had a strong foundation in systems troubleshooting and infrastructure awareness. However over time, I have realized the future is clearly transitioning toward scalable, automated infrastructure, and cloud technologies, practices are at the core of that. So I thought to myself, It was time to transition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the Environment
&lt;/h2&gt;

&lt;p&gt;I’m running Windows, I began by setting up WSL2 (Windows Subsystem for Linux), which is light, convenient, and something I already use for my day-to-day Ubuntu server administration. Because I have been comfortable with the terminal and scripting, I installed Docker Desktop and enabled WSL2 integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Setup Highlights:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Installed Docker Desktop on Windows and Enabled WSL2 backend with Ubuntu&lt;/li&gt;
&lt;/ul&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%2F3hjgdnmwodse4inkctxj.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%2F3hjgdnmwodse4inkctxj.png" alt="Image description" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verified Docker engine was running using docker version&lt;/li&gt;
&lt;/ul&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%2F04sh2a4x2miyacapniwc.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%2F04sh2a4x2miyacapniwc.png" alt="Image description" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also experimented with Podman as a daemonless alternative and successfully ran containers like nginx using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;podman run -d -P docker.io/library/nginx:1.20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running My First Minikube Cluster
&lt;/h2&gt;

&lt;p&gt;Once Docker was stable, I installed Minikube to simulate a Kubernetes cluster locally.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I did:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Installed Minikube on Ubuntu (inside WSL2)&lt;/li&gt;
&lt;/ul&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%2Fot84djwjduw2bemnp888.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%2Fot84djwjduw2bemnp888.png" alt="Image description" width="800" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Configured Docker as the default driver&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ran:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minikube start --driver=docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Verified cluster with:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minikube status
minikube profile list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was exciting to see a working cluster up and running locally. Even basic commands like checking the namespace and dashboard showed me what was going on under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges I Faced
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Docker daemon not running correctly in WSL2 initially&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Podman requiring fully qualified image names (e.g., &lt;code&gt;docker.io/library/nginx&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minikube driver issues that were fixed by restarting Docker and updating system packages&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every error was an opportunity for me to dig deeper and understand how the different tools connect. As you would agree, that's real learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next for Me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Deploy my first pod and service manually using YAML&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Learn kubectl in more depth&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start using GitHub Actions to simulate simple CI/CD workflows&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explore Helm for templating Kubernetes configs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Get hands-on with Terraform for infrastructure as code&lt;/p&gt;
&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;DevOps, Cloud-native is something we can get comfortable with, even getting to tutor others only if we put in our best time into the right resources and roadmap. It’s about mindset and approach: automation, resilience, scale. Kicking off small with Minikube and Docker is giving me the confidence to learn more. If you're transitioning from IT support or sysadmin like I am, I advise you start with what you already know and build from there, you never can tell how much you already know until you start getting your hands dirty.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>wsl2</category>
      <category>devops</category>
      <category>cloudnative</category>
      <category>docker</category>
    </item>
    <item>
      <title>My Weekend Tip 1</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Sat, 17 May 2025 17:18:13 +0000</pubDate>
      <link>https://forem.com/humjerry/my-weekend-tip-1-191o</link>
      <guid>https://forem.com/humjerry/my-weekend-tip-1-191o</guid>
      <description>&lt;p&gt;Every new role brings a fresh opportunity to learn. You never truly know how much you’ll need to unlearn and relearn until you find yourself in a team that prioritizes growth just as much as achieving company goals.&lt;br&gt;
Here’s the lesson: make yourself teachable and ready to learn. The growth we desire often comes after the willingness to be taught.&lt;/p&gt;

&lt;p&gt;There’s a subtle but important difference between the willingness to learn and the willingness to be taught. Many people hear them as the same thing but they’re not.&lt;/p&gt;

&lt;p&gt;Let's commit to learning something new every week.&lt;br&gt;
Have a great weekend, everyone.&lt;/p&gt;

</description>
      <category>improvement</category>
      <category>relearn</category>
      <category>unlearn</category>
      <category>growth</category>
    </item>
    <item>
      <title>This is how to create your first API</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Sun, 01 Dec 2024 15:16:12 +0000</pubDate>
      <link>https://forem.com/humjerry/this-is-how-to-create-your-first-api-2dpd</link>
      <guid>https://forem.com/humjerry/this-is-how-to-create-your-first-api-2dpd</guid>
      <description></description>
      <category>api</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>This is how to Optimize React Apps for Performance</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Sun, 01 Dec 2024 15:15:23 +0000</pubDate>
      <link>https://forem.com/humjerry/optimizing-react-apps-for-performance-a-comprehensive-guide-37h</link>
      <guid>https://forem.com/humjerry/optimizing-react-apps-for-performance-a-comprehensive-guide-37h</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Performance optimization in React is a best practice and more, it is very important because it directly influences the user experience. In a digital age where users are in need of fast, responsive, and seamless applications, the performance of your React app can significantly impact its level success.&lt;/p&gt;

&lt;p&gt;React with its declarative and component-Based architecture, helps developers to build dynamic and interactive user interfaces. However, as applications grow in complexity, the need for effective performance optimization becomes paramount. When a React app is well optimized, it not only loads faster but also enhances the overall user experience, giving birth to increased user engagement and satisfaction.&lt;/p&gt;

&lt;p&gt;In this comprehensive piece, we'll be looking at key strategies and techniques to optimize the performance of React applications, ensuring that they not only meet user expectations but also excel in terms of speed and responsiveness.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Bundle Size Optimization
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;2.1 Techniques for Reducing Bundle Size&lt;/strong&gt;&lt;br&gt;
 An important aspect of this optimization is reducing the bundle size of a React application, The size of your React application bundle directly correlates with its load time. Smaller bundles result in faster initial page loads and improved performance while Large bundle sizes can lead to slower loading times and increased bandwidth consumption. Let us explore some techniques for reducing the bundle size in React applications.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tree Shaking&lt;/em&gt;&lt;br&gt;
Tree shaking is a technique that involves removing unused code from a bundle. By identifying and eliminating dead code, by doing this, you can effectively reduce the overall bundle size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc. utility-library.js
export const calculateTax = (amount, taxRate) =&amp;gt; {
  return amount * (taxRate / 100);
};

export const formatCurrency = (amount, currency) =&amp;gt; {
  return new Intl.NumberFormat('en-UK', {
    style: 'currency',
    currency,
  }).format(amount);
};

//@Desc. this is an app.js
import { calculateTax } from 'utility-library';

const totalAmount = 500;
const taxRate = 8;

const taxAmount = calculateTax(totalAmount, taxRate);

console.log(`Tax Amount: ${formatCurrency(taxAmount, 'Naira')}`);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example shows the &lt;code&gt;utility-library&lt;/code&gt; contains two functions: &lt;code&gt;usedFunction&lt;/code&gt; and &lt;code&gt;unusedFunction&lt;/code&gt;. However, in the app.js file, only &lt;code&gt;usedFunction&lt;/code&gt; is imported and used.  When tree shaking is applied, the &lt;code&gt;unusedFunction&lt;/code&gt; will be detected as unused and will be removed from the final bundle. This makes only the necessary code is included in the build, thereby reducing the bundle size. We will take a look at some More in the next section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.2 Code Splitting and Dynamic Imports&lt;/strong&gt;&lt;br&gt;
Here, we will look into Code splitting and Dynamic Imports as techniques for reducing Bundle size in React applications, starting with code splitting.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;a. Code Splitting&lt;/em&gt;&lt;br&gt;
Code splitting (also known as Chunking)allows you to break down your application into smaller and more manageable Pieces, loading only the necessary parts when required. This is especially beneficial to large applications with multiple routes or features.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. this is Dashboard.js
import React, { lazy, Suspense, useState } from 'react';

const WeatherWidget = lazy(() =&amp;gt; import('./widgets/WeatherWidget'));
const CalendarWidget = lazy(() =&amp;gt; import('./widgets/CalendarWidget'));
const NewsWidget = lazy(() =&amp;gt; import('./widgets/NewsWidget'));

const Dashboard = () =&amp;gt; {
  const [selectedWidget, setSelectedWidget] = useState(null);

  const loadWidget = async (widgetName) =&amp;gt; {
    const module = await import(`./widgets/${widgetName}`);
    setSelectedWidget(module.default);
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Dashboard&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; loadWidget('WeatherWidget')}&amp;gt;Load Weather Widget&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; loadWidget('CalendarWidget')}&amp;gt;Load Calendar Widget&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; loadWidget('NewsWidget')}&amp;gt;Load News Widget&amp;lt;/button&amp;gt;

      &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
        {selectedWidget &amp;amp;&amp;amp; &amp;lt;selectedWidget /&amp;gt;}
      &amp;lt;/Suspense&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Dashboard;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;considering the dashboard application above where different widgets provide various functionalities. the Dashboard component allows users to dynamically load different widgets based on their preferences. Each widget is implemented in a separate module, then the code splitting is applied using the lazy function.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;b. Lazy Loading&lt;/em&gt;&lt;br&gt;
Dynamic imports facilitate lazy loading, which means resources are  loaded only when they are needed. This approach helps reduce the initial payload size, because users don't have to wait for the entire application to load before they can interact with it. Instead of waiting, they can access the essential parts of the application right away, and the rest of the content is loaded in the background. It can be achieved in React application by using the &lt;code&gt;React.lazy&lt;/code&gt; function along with dynamic &lt;code&gt;import()&lt;/code&gt; statements.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Data Fetching and State Management
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;3.1 Efficient data fetching strategies&lt;/strong&gt;&lt;br&gt;
Here, we will be looking at React Query as a strategy for efficient data fetching. &lt;br&gt;
&lt;em&gt;a. React Query&lt;/em&gt;&lt;br&gt;
 React Query is a popular library that handles data fetching, caching, and updating in a clear and powerful way. It automatically &lt;code&gt;refetches&lt;/code&gt; data when needed and provides built-in error handling and caching mechanisms.&lt;br&gt;
Considering a &lt;code&gt;DataFetchingComponent&lt;/code&gt; that uses &lt;code&gt;useQuery&lt;/code&gt; hook to fetch data. The &lt;code&gt;QueryClientProvider&lt;/code&gt; wraps the App component, providing a global context for managing queries. The data fetched is cached automatically by React Query, and the loading state is  managed efficiently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. we have to Install React Query: npm install react-query

//@Desc. this is App.js
import React from 'react';
import { useQuery, QueryClient, QueryClientProvider } from 'react-query';

//@Desc. Create a new instance of QueryClient
const queryClient = new QueryClient();

const fetchData = async () =&amp;gt; {
  //@Desc. Simulate fetching data from an API
  const response = await fetch('https://api.example.com/data');
  const result = await response.json();
  return result;
};

const DataFetchingComponent = () =&amp;gt; {
  //@Desc. Use the useQuery hook to fetch and manage data
  const { data, isLoading } = useQuery('data', fetchData);

  if (isLoading) {
    return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Data Fetching with React Query&amp;lt;/h1&amp;gt;
      {/* Render your component with the fetched data */}
      &amp;lt;p&amp;gt;Data: {data}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

const App = () =&amp;gt; {
  return (
    //@Desc.  Wrap your application with QueryClientProvider
    &amp;lt;QueryClientProvider client={queryClient}&amp;gt;
      &amp;lt;DataFetchingComponent /&amp;gt;
    &amp;lt;/QueryClientProvider&amp;gt;
  );
};

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.2  Caching and optimizing state management&lt;/strong&gt;&lt;br&gt;
Optimizing state management is important for preventing unnecessary re-renders and ensuring a responsive user interface.  Proper state management does a lot and can significantly impact performance in React.&lt;/p&gt;

&lt;p&gt;Using React's &lt;code&gt;useMemo&lt;/code&gt; for &lt;code&gt;Memoization&lt;/code&gt;&lt;br&gt;
React's &lt;code&gt;useMemo&lt;/code&gt; hook is useful for &lt;code&gt;memoizing&lt;/code&gt; values and preventing unnecessary calculations or renders. Let's consider a scenario where a derived value is computed based on other state values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useMemo } from 'react';

const StateManagementComponent = () =&amp;gt; {
  const [value1, setValue1] = useState(10);
  const [value2, setValue2] = useState(20);

  //@Desc. Memoized calculation
  const derivedValue = useMemo(() =&amp;gt; {
    console.log('Recalculating derived value');
    return value1 + value2;
  }, [value1, value2]);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Value 1: {value1}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Value 2: {value2}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Derived Value: {derivedValue}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default StateManagementComponent;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at the illustration above, the &lt;code&gt;derivedValue&lt;/code&gt; is calculated using &lt;code&gt;useMemo&lt;/code&gt;, making sure the calculation is performed only when value1 or value2 changes, preventing unnecessary recalculations.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Core Web Vitals and React
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;4.1 Overview of Core Web Vitals metrics&lt;/strong&gt;&lt;br&gt;
Core Web Vitals are a set of three key metrics introduced by Google to help website owners understand how users see and perceive the performance, responsiveness, and visual balance of their web pages. Now let us look at the Core Web Vitals metrics which include: &lt;br&gt;
&lt;em&gt;a. Largest Contentful Paint (LCP):&lt;/em&gt; The LCP metric measures the loading performance of a web page by determining when the largest content element within the viewport has finished loading.  React, LCP in React can be optimized by code splitting, compressing assets, preloading critical resources.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;b. First Input Delay (FID):&lt;/em&gt; This metric measures the time it takes for a user's first interaction with your web page, such as clicking a button or tapping a link. To optimize FID in a React application, minimize JavaScript Execution, Use event Delegation and Prioritize critical JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;c. Cumulative Layout Shift (CLS):&lt;/em&gt; This metric measures visual stability by evaluating how often users experience unexpected layout shifts. To optimize CLS in a React application, provide size attribute for images using &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;, Avoid dynamically injecting content above the fold, Use CSS properties for sizing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.2 How React applications can meet LCP, FID, and CLS criteria&lt;/strong&gt;&lt;br&gt;
Now facing the reality question, how React apps can meet the LCP,FID and FID criteria. Let us consider the following:&lt;br&gt;
&lt;em&gt;a. Optimizing for LCP&lt;/em&gt; by efficiently load critical assets, employ lazy loading for images and components that are not immediately visible and Compress and serve images in modern formats to reduce their size.&lt;br&gt;
&lt;em&gt;b. Improving FID&lt;/em&gt; by minimizing JavaScript execution time, make use of asynchronous techniques to ensure non-blocking execution and Streamline event handlers to be concise and responsive.&lt;br&gt;
&lt;em&gt;c. Enhancing CLS&lt;/em&gt; by ensuring that content added to the DOM dynamically does not disrupt the existing layout, reserve space for images and videos with fixed dimensions to prevent sudden layout shifts and Implement animations thoughtfully to prevent unintended layout shifts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.3 Practical tips for optimizing images and fonts&lt;/strong&gt;&lt;br&gt;
Let's see some code illustrations on how we can optimize fonts and images.&lt;br&gt;
&lt;em&gt;Image optimization&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. using responsive image with the 'srcset' attribute
&amp;lt;img
  src="large-image.jpg"
  srcSet="medium-image.jpg 800w, small-image.jpg 400w"
  sizes="(max-width: 600px) 400px, (max-width: 800px) 800px, 1200px"
  alt="Responsive Image"
/&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Font optimization&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*@Desc.  using font-display: swap in CSS */
@font-face {
  font-family: 'YourFont';
  src: url('your-font.woff2') format('woff2');
  font-display: swap;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Haven seen this, let us continue to the next chapter of this article&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Lazy Loading and React Suspense
&lt;/h2&gt;

&lt;p&gt;Lazy loading as a technique that defers the loading of certain parts of your React application until they are actually needed, can significantly improve the initial page load time and user experience. React provides a built-in feature for lazy loading components using the &lt;code&gt;React.lazy&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.1 Lazy Loading React Components&lt;/strong&gt;&lt;br&gt;
Consider a scenario where you have a large component that is not critical for the initial page load. You can lazily load it when it's actually rendered in the application, look at this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. LargeComponent.js
const LargeComponent = () =&amp;gt; {
  //@Desc. Your large component logic
};

export default LargeComponent;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. App.js
import React, { lazy, Suspense } from 'react';

const LargeComponent = lazy(() =&amp;gt; import('./LargeComponent'));

const App = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
        &amp;lt;LargeComponent /&amp;gt;
      &amp;lt;/Suspense&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the above illustration, you can se the &lt;code&gt;LargeComponent&lt;/code&gt; is loaded lazily when it's actually rendered in the App component. The Suspense component is used to provide a fallback user interface (UI) while the module is being loaded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.2 Utilizing React Suspense for concurrent rendering&lt;/strong&gt;&lt;br&gt;
React Suspense is a powerful feature that allows components to "suspend" rendering while waiting for some asynchronous operation to complete, such as fetching data or loading a module. This can enhance the user experience by maintaining a smooth transition between loading states and avoiding UI flickering.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let's see how we can use React Suspense for Data Fetching&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc.  DataFetchingComponent.js
import React, { Suspense } from 'react';

const fetchData = () =&amp;gt; {
  //@Desc. Simulate fetching data from an API
  return new Promise((resolve) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      resolve('Data loaded successfully');
    }, 2000);
  });
};

const DataComponent = () =&amp;gt; {
  const data = fetchData();

  return &amp;lt;p&amp;gt;{data}&amp;lt;/p&amp;gt;;
};

const DataFetchingComponent = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
        &amp;lt;DataComponent /&amp;gt;
      &amp;lt;/Suspense&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default DataFetchingComponent;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Examining this example, the &lt;code&gt;DataFetchingComponent&lt;/code&gt; uses Suspense to handle the loading state while the &lt;code&gt;DataComponent&lt;/code&gt; is fetching data asynchronously. The fallback UI is displayed until the asynchronous operation is complete.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.3 Improving initial page load times with lazy loading&lt;/strong&gt;&lt;br&gt;
Improving initial page load times is an important aspect of optimizing the user experience in React applications. Lazy loading is  identified as a powerful technique to achieve this by deferring the loading of non-essential components until they are actually needed. Let's see how lazy loading contributes to faster initial page load times.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lazy Loading Components and Assets&lt;/em&gt;&lt;br&gt;
In a typical React application, you may have components that are not immediately visible or required for the initial view. By lazily loading these components, you can significantly reduce the initial bundle size and, consequently, the time it takes to load the page.&lt;/p&gt;

&lt;p&gt;Consider the following example where a large feature module is lazily loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. LargeFeatureModule.js
const LargeFeatureModule = () =&amp;gt; {
  // Your large feature module logic
};

export default LargeFeatureModule;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. App.js
import React, { lazy, Suspense } from 'react';

const LargeFeatureModule = lazy(() =&amp;gt; import('./LargeFeatureModule'));

const App = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
        {/* Lazily load the large feature module */}
        &amp;lt;LargeFeatureModule /&amp;gt;
      &amp;lt;/Suspense&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;UtilityFunctions&lt;/code&gt; are dynamically imported and loaded when the &lt;code&gt;ComponentUsingUtility&lt;/code&gt; is rendered. This helps reduce the initial bundle size and improves the time it takes to load the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Performance Monitoring Tools
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;6.1 Introduction to tools like Lighthouse and WebPageTest&lt;/strong&gt;&lt;br&gt;
It is important Monitor and analyze the performance of your React application, for identifying areas of improvement and ensuring a smooth user experience. Lighthouse and WebPageTest are two powerful tools for performance evaluation. Now let's see them one after another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lighthouse&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Lighthouse&lt;/em&gt; is an open-source, automated tool for improving the quality of web pages. It has audits for performance, accessibility, progressive web apps, SEO, and more. It can be run against any web page, public or requiring authentication, directly from the Chrome DevTools, from the command line, or as a Node module.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is how to use Lighthouse in Chrome DevTools:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Chrome DevTools (Ctrl+Shift+I or Cmd+Opt+I on Mac).&lt;/li&gt;
&lt;li&gt;Go to the "Audits" tab.&lt;/li&gt;
&lt;li&gt;Click on "Perform an audit" and select the desired audit categories.&lt;/li&gt;
&lt;li&gt;Click "Run audits."&lt;/li&gt;
&lt;li&gt;Lighthouse provides a detailed report with scores and recommendations for improvement.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;WebPageTest&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;WebPageTest&lt;/em&gt; is an online tool for running web performance tests on your site. It allows user to simulate the loading of a webpage under different conditions, such as various network speeds and device types. It provides a waterfall chart, filmstrip view, and detailed metrics to help you understand how your webpage loads.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is how to use WebPageTest:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visit the WebPageTest website, you can check out &lt;a href="https://www.webpagetest.org/" rel="noopener noreferrer"&gt;catchpoint&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Enter the URL of your webpage.&lt;/li&gt;
&lt;li&gt;Choose test configurations such as location, browser, and connection speed.&lt;/li&gt;
&lt;li&gt;Click "Start Test."
WebPageTest generates a comprehensive report with details about the loading process, including time to first byte (TTFB), page load time, and visual progress.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;6.2 Setting benchmarks and analyzing performance results&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Setting Benchmarks with Lighthouse&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run Lighthouse audits for your React application.&lt;/li&gt;
&lt;li&gt;Evaluate the scores and recommendations provided by Lighthouse.&lt;/li&gt;
&lt;li&gt;Set benchmarks based on industry standards or your specific performance goals.&lt;/li&gt;
&lt;li&gt;Identify areas where your application falls short and needs improvement.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Analyzing Performance Results with WebPageTest&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run WebPageTest with various configurations to simulate different user scenarios.&lt;/li&gt;
&lt;li&gt;Examine the waterfall chart to identify bottlenecks and loading patterns.&lt;/li&gt;
&lt;li&gt;Review filmstrip views to visualize how the page renders over time.&lt;/li&gt;
&lt;li&gt;Analyze metrics such as time to first byte (TTFB), start render time, and fully loaded time.&lt;/li&gt;
&lt;li&gt;Compare results across different test configurations to understand performance variations.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  7. Third-Party Libraries and Performance
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;7.1 Impact of third-party libraries on React app performance&lt;/strong&gt;&lt;br&gt;
Integrating third-party libraries into our React application can enhance functionality, also save development time. However, it's important to be mindful of the potential impact on performance. Because poorly optimized or weighty libraries can adversely affect our application's speed and user experience.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Evaluating Third-Party Libraries&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Bundle Size:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check the size of the library's distribution files.&lt;/li&gt;
&lt;li&gt;Consider using tools like &lt;code&gt;Bundlephobia&lt;/code&gt; or &lt;code&gt;Webpack&lt;/code&gt; Bundle Analyzer to analyze the impact on your bundle size.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Network Requests:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Evaluate the number of additional network requests the library introduces.&lt;/li&gt;
&lt;li&gt;Minimize external dependencies that increase the overall request count.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Execution Time:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Assess the runtime performance of the library.&lt;/li&gt;
&lt;li&gt;Look for potential bottlenecks or performance issues in the library's code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;7.2 Balancing functionality with performance considerations&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Code Splitting for Third-Party Libraries&lt;/em&gt;&lt;br&gt;
Implementing code splitting is an effective strategy to load third-party libraries only when they are required, reducing the initial page load time. Use dynamic imports to load the library lazily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. Dynamically import a third-party library
const loadThirdPartyLibrary = () =&amp;gt; import('third-party-library');

//@Desc. Component using the library
const MyComponent = () =&amp;gt; {
  const ThirdPartyLibrary = React.lazy(loadThirdPartyLibrary);

  return (
    &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
      &amp;lt;ThirdPartyLibrary /&amp;gt;
    &amp;lt;/Suspense&amp;gt;
  );
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tree Shaking for Bundle Size Optimization&lt;/strong&gt;&lt;br&gt;
Make sure your bundler, such as Webpack, supports tree shaking. Tree shaking eliminates dead code (unused exports) from your final bundle, reducing its size. Tree shaking can be more effective If the third-party library supports ES modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitor and Update Dependencies&lt;/strong&gt;&lt;br&gt;
Update your third-party libraries to benefit from performance improvements and bug fixes. Check for updates regularly and use tools like Dependabot to automate dependency updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Profile and Optimize&lt;/strong&gt;&lt;br&gt;
Profile your application using performance monitoring tools like Lighthouse and WebPageTest. Identify the impact of third-party libraries on your application's performance and optimize accordingly. Prioritize critical functionality and evaluate the necessity of each library.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Real-world Examples and Case Studies
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;8.1 Demonstrating performance improvements in actual React projects&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Case Study 1: Bundle Size Optimization
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
A React e-commerce application was facing sluggish initial page load times due to a large bundle size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Identifying and Code Splitting:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identified the product listing page as non-critical for initial rendering.&lt;/li&gt;
&lt;li&gt;Implemented code splitting using &lt;code&gt;React.lazy&lt;/code&gt; for the product listing component.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//@Desc. Before
import ProductListing from './components/ProductListing';

//@Desc. After
const ProductListing = React.lazy(() =&amp;gt; import('./components/ProductListing'));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. Tree Shaking:&lt;/strong&gt;&lt;br&gt;
Reviewed dependencies and ensured effective tree shaking.&lt;br&gt;
Updated the Webpack configuration to support tree shaking.&lt;br&gt;
&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;
Reduced the initial bundle size by 25%, resulting in a noticeable improvement in page load times, especially for users on slower networks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Case Study 2: Data Fetching Optimization
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;br&gt;
A React dashboard with dynamic data was experiencing delays in rendering and interactivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Lazy Loading with React Suspense:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implemented lazy loading for data-heavy components using React.lazy.&lt;/li&gt;
&lt;li&gt;Utilized React Suspense to gracefully handle loading states.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const LazyDataComponent = React.lazy(() =&amp;gt; import('./components/LazyDataComponent'));

const Dashboard = () =&amp;gt; {
  return (
    &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
      &amp;lt;LazyDataComponent /&amp;gt;
    &amp;lt;/Suspense&amp;gt;
  );
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. React Query for Data Management:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integrated React Query for efficient data fetching and caching.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fetchData = async () =&amp;gt; {
  const response = await fetch('https://api.example.com/dashboard-data');
  const result = await response.json();
  return result;
};

const { data, isLoading } = useQuery('dashboardData', fetchData);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;
Improved the dashboard's overall perceived performance by 30%, providing a smoother and more responsive user experience, especially when interacting with real-time data.&lt;/p&gt;

&lt;h2&gt;
  
  
  8.2 Practical takeaways for developers to implement in their projects
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Prioritize Critical Components:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify components critical for the initial view and load them upfront.&lt;/li&gt;
&lt;li&gt;Use code splitting for non-essential components to reduce initial bundle size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Optimize Data Fetching:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Employ React Suspense for lazy loading and a seamless loading experience.&lt;/li&gt;
&lt;li&gt;Consider adopting specialized libraries like React Query for efficient data management.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Regularly Audit and Update Dependencies:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep third-party libraries up to date to benefit from performance enhancements.&lt;/li&gt;
&lt;li&gt;Conduct routine audits using tools like Lighthouse and WebPageTest.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Balance Functionality with Performance:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Assess the necessity of third-party libraries and features.&lt;/li&gt;
&lt;li&gt;Strive for a balanced approach, optimizing functionality without compromising performance.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;making React apps faster is like putting together a puzzle. You need to make smart choices, follow good practices, and use the right tools. Throughout this guide, we looked at different ways to speed up React apps, like making the initial load quicker and fetching data more efficiently. The real-world examples showed how these tricks can solve real problems. I hope this guide helps you make your React apps speedy and smooth.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>optimization</category>
      <category>learning</category>
    </item>
    <item>
      <title>Optimizing React Apps for Performance: A Comprehensive Guide</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Tue, 02 Apr 2024 09:46:29 +0000</pubDate>
      <link>https://forem.com/humjerry/optimizing-react-apps-for-performance-a-comprehensive-guide-2jff</link>
      <guid>https://forem.com/humjerry/optimizing-react-apps-for-performance-a-comprehensive-guide-2jff</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;In addition to being a best practice, performance optimization in &lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;React&lt;/a&gt; is crucial since it affects the user experience directly. The speed and responsiveness of your React app are critical factors in determining its level of success in the modern digital world, where customers want seamless, quick, and uninterrupted experiences.&lt;/p&gt;

&lt;p&gt;React's declarative, component-based architecture facilitates the creation of dynamic, interactive user interfaces by developers. But as applications get more complicated, it becomes more and more important to optimize performance effectively. A well-optimized React application not only loads more quickly but also improves the user experience overall, increasing user happiness and engagement.&lt;/p&gt;

&lt;p&gt;This in-depth article will examine important tactics and methods for enhancing React applications' performance so that they not only live up to user expectations but also run exceptionally quickly and responsively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundle Size Optimization
&lt;/h2&gt;

&lt;p&gt;The process of reducing a web application's or software package's overall size to make it more effective and quicker to load is known as bundle size optimization in web development and software engineering. Let us explore some techniques for reducing bundle size.&lt;/p&gt;

&lt;h3&gt;
  
  
  Techniques for Reducing Bundle Size
&lt;/h3&gt;

&lt;p&gt;Reducing a &lt;code&gt;React&lt;/code&gt; application's bundle size is a crucial part of this optimization process, as the size of your React application bundle directly affects how quickly it loads. Larger bundle sizes can result in slower loading times and more bandwidth consumption, whereas smaller bundles improve performance and the speed at which pages load initially. Now let's look at several methods for making &lt;code&gt;React&lt;/code&gt; apps' bundle sizes smaller.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tree Shaking
&lt;/h3&gt;

&lt;p&gt;Tree shaking is a technique that involves removing unused code from a bundle. By identifying and eliminating dead code, you can effectively reduce the overall bundle size.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// @Desc. utility-library.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculateTax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;taxRate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formatCurrency&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NumberFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en-UK&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;currency&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. this is an app.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;calculateTax&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utility-library&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;totalAmount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;taxAmount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateTax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalAmount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Tax Amount: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;formatCurrency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;taxAmount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Naira&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The example shows the &lt;code&gt;utility library&lt;/code&gt; contains two functions: &lt;code&gt;usedFunction&lt;/code&gt; and &lt;code&gt;unusedFunction&lt;/code&gt;. However, in the app.js file, only &lt;code&gt;usedFunction&lt;/code&gt; is imported and used. When tree shaking is applied, the &lt;code&gt;unusedFunction&lt;/code&gt; will be detected as unused and will be removed from the final bundle. This means only the necessary code is included in the build, thereby reducing the bundle size. We will take a look at some more in the next section.&lt;/p&gt;
&lt;h2&gt;
  
  
  Code Splitting and Dynamic Import
&lt;/h2&gt;

&lt;p&gt;Here, we will look into code splitting and dynamic imports as techniques for reducing bundle size in React applications, starting with code splitting.&lt;/p&gt;
&lt;h3&gt;
  
  
  Code Splitting
&lt;/h3&gt;

&lt;p&gt;Code splitting (also known as chunking) allows you to break down your application into smaller and more manageable pieces, loading only the necessary parts when required. This is especially beneficial for large applications with multiple routes or features.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. this is Dashboard.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WeatherWidget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./widgets/WeatherWidget&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CalendarWidget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./widgets/CalendarWidget&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NewsWidget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./widgets/NewsWidget&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Dashboard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;selectedWidget&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSelectedWidget&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadWidget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;widgetName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`./widgets/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;widgetName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setSelectedWidget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Dashboard&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;loadWidget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;WeatherWidget&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Load&lt;/span&gt; &lt;span class="nx"&gt;Weather&lt;/span&gt; &lt;span class="nx"&gt;Widget&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;loadWidget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;CalendarWidget&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Load&lt;/span&gt; &lt;span class="nx"&gt;Calendar&lt;/span&gt; &lt;span class="nx"&gt;Widget&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;loadWidget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NewsWidget&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Load&lt;/span&gt; &lt;span class="nx"&gt;News&lt;/span&gt; &lt;span class="nx"&gt;Widget&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;selectedWidget&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;selectedWidget&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Dashboard&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;considering the dashboard application above where different widgets provide various functionalities. the Dashboard component allows users to dynamically load different widgets based on their preferences. Each widget is implemented in a separate module, then the code splitting is applied using the lazy function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lazy Loading
&lt;/h3&gt;

&lt;p&gt;Dynamic imports facilitate lazy loading, which means resources are loaded only when they are needed. This approach helps reduce the initial payload size because users don't have to wait for the entire application to load before they can interact with it. Instead of waiting, they can access the essential parts of the application right away, and the rest of the content is loaded in the background. It can be achieved in a React application by using the &lt;code&gt;React.lazy&lt;/code&gt; function along with dynamic &lt;code&gt;import()&lt;/code&gt; statements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Fetching and State Management
&lt;/h2&gt;

&lt;p&gt;When developing web and mobile applications, two key ideas are data fetching and state management.The process of integrating data into an application by getting information from several sources, including local storage, databases, and &lt;code&gt;APIs&lt;/code&gt;, is known as &lt;code&gt;data fetching&lt;/code&gt;.On the other hand, state management is the process of keeping the user interface and data of an application updated and synced over time. User interactions, additional dynamic features, and the data shown on the screen make up the state of an online or mobile application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Efficient data fetching strategies
&lt;/h3&gt;

&lt;p&gt;In React apps, efficient data fetching is essential for a seamless user experience. Ineffective data fetching techniques can have a detrimental effect on performance by causing sluggish interfaces and long load times.&lt;/p&gt;

&lt;p&gt;An application may become less responsive if data fetching is not optimized, as this may cause needless delays in the rendering of component parts. Keeping the user interface in sync with the data might be difficult when state management is inefficient.&lt;/p&gt;

&lt;p&gt;React developers frequently use libraries that focus on state management and data fetching to overcome these difficulties. &lt;code&gt;ReactQuery&lt;/code&gt; is one handy tool in this regard. It is notable for how well it manages the application state and duties related to data fetching.&lt;/p&gt;

&lt;h3&gt;
  
  
  React Query
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/react-query" rel="noopener noreferrer"&gt;ReactQuery&lt;/a&gt; is a popular library that handles data fetching, caching, and updating in a clear and powerful way. It automatically refetches data when needed and provides built-in error handling and caching mechanisms.Considering a &lt;code&gt;DataFetchingComponent&lt;/code&gt; that uses the &lt;code&gt;useQuery&lt;/code&gt; hook to fetch data. The &lt;code&gt;QueryClientProvider&lt;/code&gt; wraps the App component, providing a global context for managing queries. The data fetched is cached automatically by React Query, and the loading state is managed efficiently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. we have to Install React Query: npm install react-query&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. this is App.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;QueryClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;QueryClientProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-query&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. Create a new instance of QueryClient&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueryClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//@Desc. Simulate fetching data from an API&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DataFetchingComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//@Desc. Use the useQuery hook to fetch and manage data&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Data&lt;/span&gt; &lt;span class="nx"&gt;Fetching&lt;/span&gt; &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Render your component with the fetched data */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;//@Desc.  Wrap your application with QueryClientProvider&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;QueryClientProvider&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryClient&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DataFetchingComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/QueryClientProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above shows that the required components are imported, an instance of &lt;code&gt;QueryClient&lt;/code&gt; is created, a data fetching function is defined, and data is fetched and managed using the &lt;code&gt;useQuery&lt;/code&gt; hook inside a component. In order to make the &lt;code&gt;QueryClient&lt;/code&gt; available throughout the application, the main component wraps the data fetching component with &lt;code&gt;QueryClientProvider&lt;/code&gt;. Finally, it exports the main component as the entry point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caching and optimizing state management
&lt;/h2&gt;

&lt;p&gt;Optimizing state management is important for preventing unnecessary re-renders and ensuring a responsive user interface. Proper state management does a lot and can significantly impact performance in React.&lt;/p&gt;

&lt;p&gt;Using React's &lt;a href="https://react.dev/reference/react/useMemo" rel="noopener noreferrer"&gt;useMemo&lt;/a&gt; for Memoization&lt;br&gt;
React's &lt;code&gt;useMemo&lt;/code&gt; hook is useful for memoizing values and preventing unnecessary calculations or renders. Let's consider a scenario where a derived value is computed based on other state values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useMemo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StateManagementComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;//@Desc. Memoized calculation&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;derivedValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Recalculating derived value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Value&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Value&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Derived&lt;/span&gt; &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;derivedValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;StateManagementComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at the illustration above, the &lt;code&gt;derivedValue&lt;/code&gt; is calculated using &lt;code&gt;useMemo&lt;/code&gt;, making sure the calculation is performed only when value1 or value2 changes, preventing unnecessary recalculations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Web Vitals and React
&lt;/h2&gt;

&lt;p&gt;Core Web Vitals are a set of three key metrics introduced by Google to help website owners understand how users see and perceive the performance, responsiveness, and visual balance of their web pages. Now let us look at the Core Web Vitals metrics, which include: &lt;/p&gt;

&lt;h3&gt;
  
  
  Largest Contentful Paint (LCP)
&lt;/h3&gt;

&lt;p&gt;The LCP metric measures the loading performance of a web page by determining when the largest content element within the viewport has finished loading. &lt;code&gt;React&lt;/code&gt;, LCP in React can be optimized by code splitting, compressing assets, and preloading critical resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  First Input Delay (FID)
&lt;/h3&gt;

&lt;p&gt;This metric measures the time it takes for a user's first interaction with your web page, such as clicking a button or tapping a link. To optimize FID in a React application, minimize &lt;a href="https://www.javascript.com/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt; execution, use event delegation, and prioritize critical &lt;code&gt;JavaScript&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cumulative Layout Shift (CLS)
&lt;/h3&gt;

&lt;p&gt;This metric measures visual stability by evaluating how often users experience unexpected layout shifts. To optimize CLS in a React application, provide size attributes for images using &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;, Avoid dynamically injecting content above the fold. Use CSS properties for sizing.&lt;/p&gt;

&lt;h2&gt;
  
  
  How React applications can meet LCP, FID, and CLS criteria
&lt;/h2&gt;

&lt;p&gt;Now facing the reality question of how React apps can meet the LCP, FID, and FID criteria. Let us consider the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimizing for LCP by efficiently loading critical assets, employing lazy loading for images and components that are not immediately visible, and compressing and serving images in modern formats to reduce their size.&lt;/li&gt;
&lt;li&gt; Improving FID by minimizing JavaScript execution time, making use of asynchronous techniques to ensure non-blocking execution, and streamlining event handlers to be concise and responsive.&lt;/li&gt;
&lt;li&gt;Enhancing CLS by ensuring that content added to the DOM dynamically does not disrupt the existing layout; reserve space for images and videos with fixed dimensions to prevent sudden layout shifts; and implement animations thoughtfully to prevent unintended layout shifts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Practical tips for optimizing images and fonts
&lt;/h2&gt;

&lt;p&gt;Let's see some code illustrations on how we can optimize fonts and images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image optimization
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;CSS&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="k"&gt;@Desc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;using&lt;/span&gt; &lt;span class="n"&gt;responsive&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="s2"&gt;'srcset'&lt;/span&gt; &lt;span class="n"&gt;attribute&lt;/span&gt;
&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;
  &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"large-image.jpg"&lt;/span&gt;
  &lt;span class="n"&gt;srcSet&lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"medium-image.jpg 800w, small-image.jpg 400w"&lt;/span&gt;
  &lt;span class="n"&gt;sizes&lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"(max-width: 600px) 400px, (max-width: 800px) 800px, 1200px"&lt;/span&gt;
  &lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"Responsive Image"&lt;/span&gt;
&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Font optimization
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/*@Desc.  using font-display: swap in CSS */&lt;/span&gt;
&lt;span class="k"&gt;@font-face&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'YourFont'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;src&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('your-font.woff2')&lt;/span&gt; &lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;'woff2'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;font-display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first CSS illustration above optimizes image loading by utilizing the &lt;code&gt;srcset&lt;/code&gt; attribute in an &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag. It provides multiple image sources with different resolutions to accommodate various screen sizes and device capabilities, ensuring an optimal user experience. While the second CSS example for font optimization utilizes the font-display: swap to improve font loading by displaying text immediately with a fallback font while asynchronously loading the custom font in the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lazy Loading and React Suspense
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/reference/react/lazy" rel="noopener noreferrer"&gt;Lazyloading&lt;/a&gt; as a technique that defers the loading of certain parts of your React application until they are actually needed, can significantly improve the initial page load time and user experience. React provides a built-in feature for lazy loading components using the &lt;code&gt;React.lazy&lt;/code&gt; function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lazy Loading React Components
&lt;/h3&gt;

&lt;p&gt;Consider a scenario where you have a large component that is not critical for the initial page load. You can lazily load it when it's actually rendered in the application. Look at this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. LargeComponent.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LargeComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//@Desc. Your large component logic&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;LargeComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. App.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LargeComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./LargeComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LargeComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the above illustration, you can see that the &lt;code&gt;LargeComponent&lt;/code&gt; is loaded lazily when it's actually rendered in the App component. The Suspense component is used to provide a fallback user interface (UI) while the module is being loaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  Utilizing React Suspense for concurrent rendering
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://react.dev/reference/react/Suspense" rel="noopener noreferrer"&gt;ReactSuspense&lt;/a&gt; is a powerful feature that allows components to &lt;code&gt;suspend&lt;/code&gt; rendering while waiting for some asynchronous operation to complete, such as fetching data or loading a module. This can enhance the user experience by maintaining a smooth transition between loading states and avoiding UI flickering.&lt;br&gt;
Let's see how we can use React Suspense for Data Fetching:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc.  DataFetchingComponent.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//@Desc. Simulate fetching data from an API&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Data loaded successfully&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DataComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DataFetchingComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DataComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;DataFetchingComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Examining this example, the &lt;code&gt;DataFetchingComponent&lt;/code&gt; uses Suspense to handle the loading state while the &lt;code&gt;DataComponent&lt;/code&gt; is fetching data asynchronously. The fallback UI is displayed until the asynchronous operation is complete.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improving initial page load times with lazy loading
&lt;/h3&gt;

&lt;p&gt;Improving initial page load times is an important aspect of optimizing the user experience in React applications. Lazy loading is identified as a powerful technique to achieve this by deferring the loading of non-essential components until they are actually needed. Let's see how lazy loading contributes to faster initial page load times.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lazy Loading Components and Assets
&lt;/h3&gt;

&lt;p&gt;In a typical React application, you may have components that are not immediately visible or required for the initial view. By lazily loading these components, you can significantly reduce the initial bundle size and, consequently, the time it takes to load the page.Consider the following example, where a large feature module is lazily loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;JavaScript&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//@Desc. LargeFeatureModule.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LargeFeatureModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your large feature module logic&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;LargeFeatureModule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. App.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LargeFeatureModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./LargeFeatureModule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Lazily load the large feature module */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LargeFeatureModule&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;UtilityFunctions&lt;/code&gt; are dynamically imported and loaded when the &lt;code&gt;ComponentUsingUtility&lt;/code&gt; is rendered. This helps reduce the initial bundle size and improves the time it takes to load the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Monitoring Tools
&lt;/h2&gt;

&lt;p&gt;These are software programs or services that are used by IT specialists, system administrators, and developers to assess, evaluate, and improve the efficiency of their networks, systems, and applications. In this article, we are focusing on web performance monitoring tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction to tools like Lighthouse and WebPageTest
&lt;/h3&gt;

&lt;p&gt;It is important to monitor and analyze the performance of your React application to identify areas for improvement and ensure a smooth user experience. Lighthouse and &lt;code&gt;WebPageTest&lt;/code&gt; are two powerful tools for performance evaluation. Now let's see them one after another.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lighthouse
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Lighthouse&lt;/code&gt; is an open-source, automated tool for improving the quality of web pages. It has audits for performance, accessibility, progressive web apps, SEO, and more. It can be run against any web page, public or requiring authentication, directly from the Chrome DevTools, from the command line, or as a Node module.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Lighthouse in Chrome DevTools
&lt;/h3&gt;

&lt;p&gt;Below is a list of how to use Lighthouse in Chrome Dev Tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Open Chrome DevTools (Ctrl+Shift+I or Cmd+Opt+I on Mac).&lt;/li&gt;
&lt;li&gt; Go to the "Audits" tab.&lt;/li&gt;
&lt;li&gt; Click on "Perform an audit" and select the desired audit categories.&lt;/li&gt;
&lt;li&gt; Click "Run audits."&lt;/li&gt;
&lt;li&gt; Lighthouse provides a detailed report with scores and recommendations for improvement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  WebPageTest
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;WebPageTest&lt;/code&gt; is an online tool for running web performance tests on your site. It allows users to simulate the loading of a webpage under different conditions, such as various network speeds and device types. It provides a waterfall chart, a filmstrip view, and detailed metrics to help you understand how your webpage loads.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to use WebPageTest
&lt;/h3&gt;

&lt;p&gt;Here is how to use webpagetest:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Visit the WebPageTest website, you can check out &lt;a href="https://www.webpagetest.org/" rel="noopener noreferrer"&gt;catchpoint&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Enter the URL of your webpage.&lt;/li&gt;
&lt;li&gt; Choose test configurations such as location, browser, and connection speed.&lt;/li&gt;
&lt;li&gt; Click "Start Test."
&lt;code&gt;WebPageTest&lt;/code&gt; generates a comprehensive report with details about the loading process, including time to first byte (TTFB), page load time, and visual progress.
###  Setting Benchmarks with Lighthouse
Start with Lighthouse audits to maximize the performance of your React application. Evaluate Lighthouse's scores and suggestions with careful consideration. Next, set benchmarks that are in line with industry norms or customized to meet your unique performance goals. Lastly, pay close attention to the places in your application where it needs work. You can improve your React application's effectiveness by carefully following these procedures, which will guarantee that it satisfies the required performance requirements.
### Analyzing Performance Results with WebPageTest
In order to fully evaluate your webpage's performance, launch &lt;code&gt;WebPageTest&lt;/code&gt; with a variety of systems, simulating a variety of user scenarios. Examine the waterfall chart carefully to identify loading patterns and bottlenecks, which are essential for improving the user experience. To see the page's rendering process over time and do a thorough examination, use filmstrip views. To effectively assess performance, pay special attention to measures such as time to first byte (TTFB), start render time, and fully loaded time. Also, a better understanding of performance variances is made possible by comparing findings across various test designs, which helps make well-informed recommendations for improving webpage responsiveness and efficiency.
## Impact of third-party libraries on React app performance
Third-party library integration can speed up development while improving functionality in our React application. It's crucial to consider the possible effects on performance, though. Because heavy or poorly optimized libraries might negatively impact the speed and usability of our application.
### Bundle Size
Look at the distribution file sizes related to the library, and use tools such as &lt;a href="https://bundlephobia.com/" rel="noopener noreferrer"&gt;Bundlephobia&lt;/a&gt; or &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt; Bundle Analyzer to fully evaluate their impact on your bundle size. This thorough analysis enables you to make well-informed decisions about whether to include the library, making sure that its contribution minimizes superfluous bulk in your application's codebase and is in line with your optimization goals.
### Network Requests
Analyze how the third-party library affects network requests to maximize performance. Reduce the number of requests made overall by minimizing external dependencies. This will enhance the user experience and loading speeds. Select appropriate libraries, maximize asset delivery, and leverage code splitting to load components asynchronously. You may improve the effectiveness and responsiveness of your application and provide users with a better experience by cutting down on pointless network queries.
### Execution Time
Examine the library's code for any possible performance problems or bottlenecks in order to analyze the runtime performance of the library. Look for places where the code may execute slowly or inefficiently. You may ensure smoother operation inside your application by identifying and addressing any areas of the library's implementation that may be impeding ideal performance by doing a comprehensive assessment.
### Code Splitting for Third-Party Libraries
Implementing code splitting is an effective strategy to load third-party libraries only when they are required, reducing the initial page load time. Use dynamic imports to load the library lazily:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. Dynamically import a third-party library&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadThirdPartyLibrary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;third-party-library&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. Component using the library&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ThirdPartyLibrary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loadThirdPartyLibrary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ThirdPartyLibrary&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code illustration dynamically imports a third-party library using React's &lt;code&gt;React.lazy()&lt;/code&gt; and Suspense for code-splitting and lazy loading.&lt;br&gt;
In the MyComponent functional component, &lt;code&gt;React.lazy()&lt;/code&gt; is used to dynamically import the component returned by &lt;code&gt;loadThirdPartyLibrary&lt;/code&gt;. The imported component is then rendered within a Suspense component, which displays a loading indicator while the component is being loaded asynchronously.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tree Shaking for Bundle Size Optimization
&lt;/h3&gt;

&lt;p&gt;Make sure your bundler, such as Webpack, supports tree shaking. Tree shaking eliminates dead code (unused exports) from your final bundle, reducing its size. Tree shaking can be more effective if the third-party library supports ES modules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Monitor and update dependencies
&lt;/h3&gt;

&lt;p&gt;Update your third-party libraries to benefit from performance improvements and bug fixes. Check for updates regularly, and use tools like Dependabot to automate dependency updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Profile and Optimize
&lt;/h3&gt;

&lt;p&gt;Profile your application using performance monitoring tools like &lt;code&gt;Lighthouse&lt;/code&gt; and &lt;code&gt;WebPageTest&lt;/code&gt;. Identify the impact of third-party libraries on your application's performance and optimize accordingly. Prioritize critical functionality and evaluate the necessity of each library.&lt;/p&gt;

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

&lt;p&gt;Making &lt;code&gt;React&lt;/code&gt; apps faster is like putting together a puzzle. You need to make smart choices, follow good practices, and use the right tools. Throughout this guide, we looked at different ways to speed up &lt;code&gt;React&lt;/code&gt; apps, like making the initial load quicker and fetching data more efficiently. The real-world examples showed how these tricks can solve real problems. I hope this guide helps you make your React apps speedy and smooth.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Uncovering Middleware in Node.js and Express: A Comprehensive Guide</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Sat, 10 Feb 2024 15:49:47 +0000</pubDate>
      <link>https://forem.com/humjerry/uncovering-middleware-in-nodejs-and-express-a-comprehensive-guide-39p7</link>
      <guid>https://forem.com/humjerry/uncovering-middleware-in-nodejs-and-express-a-comprehensive-guide-39p7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Middleware is a crucial concept in the world of &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; and Express, and it can be a bit confusing for new developers. In this comprehensive guide, we'll dive into middleware elaborately, exploring its fundamental concepts in detail while showing hands-on examples to help cut down its role in shaping web applications.&lt;/p&gt;

&lt;p&gt;Middleware is a function that has access to the request and response objects, as well as the next function in the application's request-response cycle. The functions can perform various tasks, such as logging requests, authenticating users, parsing request bodies, and serving static files.&lt;br&gt;
It is used to add functionality to an application without coupling it to a specific route or controller. This makes it a powerful tool for organizing and modularizing application logic, as well as for reusing code across multiple routes and controllers. Now let's see the..&lt;/p&gt;
&lt;h2&gt;
  
  
  Unveiling the Essence of Middleware in Node.js and Express
&lt;/h2&gt;

&lt;p&gt;In web application development using &lt;code&gt;Node.js&lt;/code&gt; and &lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;Express&lt;/a&gt;, middleware functions serve as the unseen mediator between incoming requests and server responses. They enable developers to apply logic at crucial stages of the request-response cycle. These middleware functions execute sequentially, with each contributing to the orchestration of the processing flow.&lt;/p&gt;
&lt;h3&gt;
  
  
  Application-Level Middleware
&lt;/h3&gt;

&lt;p&gt;At the broadest level viewpoint, middleware that runs at the application level (application-level middleware) has a significant impact on the entire Express application. In simpler terms, when we use middleware like &lt;a href="https://expressjs.com/en/resources/middleware/serve-static.html" rel="noopener noreferrer"&gt;express.static&lt;/a&gt; to serve static files, it affects the entire Express application. Now Let's look into how we can use &lt;code&gt;express.static&lt;/code&gt; to serve static files with ease.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. Serving static files from the 'public' directory&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Router-Level Middleware
&lt;/h3&gt;

&lt;p&gt;Router-level middleware refers to functions that are executed before a route handler is called in a &lt;code&gt;Node.js&lt;/code&gt; application. These middleware functions can be bound to specific routes or groups of routes at the router level instead of being applied globally at the application level using app-level middleware. &lt;/p&gt;

&lt;p&gt;In terms of user authentication using middleware, this involves implementing middleware functions that check whether a user is authenticated before allowing them access to certain routes or resources in an application. &lt;/p&gt;

&lt;p&gt;A common approach to user authentication using middleware is to create a middleware function that checks for the presence of a valid authentication token in the request headers or cookies. If the token is valid, the user is considered authenticated and the request is passed on to the route handler. If the token is not valid or missing, the user is redirected to a login page or denied access to the resource altogether with an appropriate error message or status code returned to them instead of executing the route handler function as usual would do so if authentication was successful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. Middleware to authenticate users&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authenticateUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Logic to authenticate user&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;

  &lt;span class="c1"&gt;//@Desc. If authenticated, proceed to the next middleware&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. Applying middleware to a specific route&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/protected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authenticateUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Welcome to the protected route!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Error-Handling Middleware
&lt;/h3&gt;

&lt;p&gt;These middleware functions intercept errors at the router or application level, providing a mechanism for logging, responding, and handling errors in a graceful and consistent manner.&lt;/p&gt;

&lt;p&gt;The process of implementing error-handling middleware involves creating a middleware function that takes a request object (req), a response object (res), and a next function (next) as arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//@Desc. Error-handling middleware&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;errorHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Something gone wrong!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//@Desc. Applying error-handling middleware&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any faults that arise throughout the request handling process are safely tucked away by the &lt;a href="https://expressjs.com/en/guide/error-handling.html" rel="noopener noreferrer"&gt;errorHandler&lt;/a&gt; middleware.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crafting a Symphony with Logging Middleware
&lt;/h3&gt;

&lt;p&gt;Our first practical voyage unfolds as we create a logging middleware, giving a log entry for each incoming request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logMiddleware&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logMiddleware&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Authentication Middleware
&lt;/h3&gt;

&lt;p&gt;Moreover, we provide an authentication middleware that restricts access to particular routes to only authenticated entities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;authenticateMiddleware&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//@Desc. Check if the user is logged in&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isAuthenticated&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Unauthorized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/dashboard&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authenticateMiddleware&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Welcome to the dashboard!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;authenticateMiddleware&lt;/code&gt; stands sentinel, allowing only the authenticated to bask in the dashboard's radiance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;In web development, middleware acts as an unseen conductor, balancing the logic and data flow by intercepting requests and answers in the application's execution chain. You can write apps that behave with robustness and clarity by learning middleware.&lt;/p&gt;

</description>
      <category>node</category>
      <category>middleware</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Understanding RESTful API Development with Node.js and Express: A Guide to Controller Methods</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Fri, 09 Feb 2024 13:19:15 +0000</pubDate>
      <link>https://forem.com/humjerry/understanding-restful-api-development-with-nodejs-and-express-a-guide-to-controller-methods-2al1</link>
      <guid>https://forem.com/humjerry/understanding-restful-api-development-with-nodejs-and-express-a-guide-to-controller-methods-2al1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Building a scalable and efficient RESTful API is a critical aspect of modern web development. In this comprehensive guide, we'll look at the intricacies of designing controller methods in Node.js using the Express framework. From structuring routes to handling errors and implementing secure authentication, Will all be covered with code examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Section 1: Designing Robust Routes and Controller Methods
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.1 Organizing Routes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To have a solid foundation for a well-structured Node.js application, it is essential to focus on the organization of routes. This involves creating modular route handlers that are seamlessly linked to their corresponding controller methods. By implementing this approach, not only can developers greatly enhance the overall clarity and maintainability of their code but also ensure that the routing aligns very well with the intended outcome. Achieving a high level of clarity and maintainability within the application's routing system can have great benefits, such as improving the ease of understanding, debugging, and modifying the routes.  By decoupling the logic of handling requests from the actual routing code, developers can realize the advantage of separation of concerns, allowing for easier code maintenance, code reuse, and collaboration between team members. This way, the Node.js application is capable of accommodating changes and additions to the routing layer seamlessly. thanks to the well-organized modular route handlers and their direct connections to the respective controller methods. Ultimately, this results in an architecture that not only promotes codebase organization and maintainability but also lays the groundwork for future growth and scalability of the Node.js application as a whole. See code block below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc Structuring Routes
const express = require('express');
const router = express.Router();

const UserController = require('./controllers/UserController');

router.get('/users', UserController.getAllUsers);
router.get('/users/:id', UserController.getUserById);
// Additional routes...

module.exports = router;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1.2 Implementing Controller Methods
&lt;/h2&gt;

&lt;p&gt;This is where we'll look at the best ways to write clean and modular code that can handle different types of actions like getting, adding, updating, and deleting data using HTTP methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc. UserController.js
class UserController {
  static async getAllUsers(req, res) {
    // Logic to retrieve all users
  }

  static async getUserById(req, res) {
    // Logic to retrieve a user by ID
  }
  // Additional controller methods...
}

module.exports = UserController;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Section 2: Effective Error Handling in Controller Methods
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;2.1 Error Middleware&lt;/strong&gt;&lt;br&gt;
Here we'll see how to implement error middleware to centralize error handling within your Express application, making the code more maintainable and user-friendly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc. Error Middleware
function errorHandler(err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Something went wrong!');
}

// Implementing in Express
const express = require('express');
const app = express();

app.use(errorHandler);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.2 Status Codes and Meaningful Messages&lt;/strong&gt;&lt;br&gt;
understanding how to use HTTP status codes effectively and providing meaningful error messages empowers developers to create applications with enhanced user experiences. Clear communication, robust error handling, swift error recovery, consistency, and informed decision-making through analytics are some of the critical benefits that this knowledge brings to developers looking to deliver high-quality, user-centric applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc. Status Codes and Messages
class UserController {
  static async getUserById(req, res) {
    try {
      // Logic to retrieve a user by ID
    } catch (error) {
      res.status(404).json({ error: 'User not found' });
    }
  }
  // Additional error handling...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Section 3: Securing Your Node.js Application with Authentication
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;3.1 User Authentication&lt;/strong&gt;&lt;br&gt;
Authentication is a process of verifying the identity of a user or application that is attempting to access a protected resource or service. Implementing user authentication in Node.js controller methods is crucial for developers who want to ensure secure access to their APIs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc. User Authentication
const jwt = require('jsonwebtoken');

class AuthController {
  static async authenticateUser(req, res) {
    // Logic to authenticate user
    const token = jwt.sign({ userId: user.id }, 'secret-key');
    res.json({ token });
  }
  // Additional authentication methods...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.2 Authorization Middleware&lt;/strong&gt;&lt;br&gt;
To ensure the security and integrity of your application's data and resources, implementing authorization middleware is crucial. By controlling access to specific routes and resources based on user roles, you can prevent unauthorized access and protect sensitive information. This helps to prevent data breaches, maintain data confidentiality, and ensure compliance with regulatory requirements. Additionally, implementing authorization middleware can improve the user experience by providing access to relevant resources and preventing unnecessary errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @Desc. Authorization Middleware
function isAdmin(req, res, next) {
  if (req.user.role === 'admin') {
    next();
  } else {
    res.status(403).json({ error: 'Unauthorized' });
  }
}

// Implementing in Express
const express = require('express');
const app = express();

app.get('/admin-route', isAdmin, (req, res) =&amp;gt; {
  res.json({ message: 'Admin access granted' });
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;Creating controller methods in Node.js with Express is important for building reliable and secure web applications with RESTful APIs. By organizing routes in a clear and efficient way, handling errors properly, and adding authentication to protect sensitive information, you can create scalable, maintainable, and secure applications that provide a great user experience. This skillset is essential for any developer looking to build reliable web applications using Node.js and Express.&lt;/p&gt;

</description>
      <category>express</category>
      <category>node</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Appealing Console Output with Colors.js</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Thu, 01 Feb 2024 19:01:04 +0000</pubDate>
      <link>https://forem.com/humjerry/appealing-console-output-with-colorsjs-1o8o</link>
      <guid>https://forem.com/humjerry/appealing-console-output-with-colorsjs-1o8o</guid>
      <description>&lt;p&gt;Many developers often overlook this package in the development of their APIs with Node.js. Is it worth it? Is it even necessary? Will my code not run fine if I don't have it installed? The answer is NO. However, using the colors.js package gives an appealing visual and a better console output, giving room for easy debugging process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start this way
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Get the 'Colors.js' Installed&lt;/strong&gt;&lt;br&gt;
the first thing to be done is to install the package. to do this open up your terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after running the command, the Node package manager (NPM) installs the package for you in a few seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Now require the 'colors.js' in your script:&lt;/strong&gt;&lt;br&gt;
now that you have the package installed, next is to require the package into you main script. Run this line of code to achieve it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;colors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the above line of code imports the 'colors.js' module, thus allowing the developer explore what it offers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apply colors to the console output
&lt;/h2&gt;

&lt;p&gt;take this simple line of code for instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;get high paying jobs when you code in&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;or keep earning little while coding in&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;red&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  You can "underline" and make output "bold"
&lt;/h2&gt;

&lt;p&gt;by simply doing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Let the lines be underlined and bold&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;underline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the "colors.js" can be used in several ways to make our console logs visually appealing. you can learn more when you visit &lt;a href="https://www.npmjs.com/package/colors" rel="noopener noreferrer"&gt;colors.js&lt;/a&gt;. So many things for you to try out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;I really recommend the "colors.js" for Node.js console output as it helps make our output visually appealing and debugging easier and faster.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>node</category>
      <category>console</category>
    </item>
    <item>
      <title>Set up your Node.js environment in few seconds.</title>
      <dc:creator>Humjerry⚓</dc:creator>
      <pubDate>Fri, 29 Dec 2023 14:11:46 +0000</pubDate>
      <link>https://forem.com/humjerry/set-up-your-nodejs-environment-in-few-seconds-59jm</link>
      <guid>https://forem.com/humjerry/set-up-your-nodejs-environment-in-few-seconds-59jm</guid>
      <description>&lt;p&gt;Wondering how to set up your Node.js environment and real quick? here is a simple and really quick guide to achieving just that.&lt;br&gt;
In order achieve this we will have to install the tools listed below.&lt;/p&gt;

&lt;h3&gt;
  
  
  What We Need
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Node.js:
&lt;/h3&gt;

&lt;p&gt;This is a cross-platform and open source JavaScript runtime environment. It allows for server side scripting and lets developers use JavaScript to write command line tools. &lt;br&gt;
to install this go to&lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;&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%2Fgcir5f1kfr9zcdpngyta.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%2Fgcir5f1kfr9zcdpngyta.png" alt="Image showing the download page of nodejs" width="800" height="344"&gt;&lt;/a&gt;&lt;br&gt;
Once you get here (the download page), you can either download the long term support version or the latest version, select the OS your PC is running on, the bit and hit download. This comes with the Node package manager (NPM) which is a library and registry for JavaScript software packages, you would definitely need it for your installations. After this is done the next should be the..&lt;/p&gt;

&lt;h2&gt;
  
  
  VS Code:
&lt;/h2&gt;

&lt;p&gt;which stands for visual studio code is a  cross-platform text editor. Their are other text editors you can use, but I prefer and recommend VS Code as it is powerful and simple at same time and it is arguably the most popular text editor in the software development industry. Getting the VS Code into your PC is a easy as checking out &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;visualstudio.com&lt;/a&gt;&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%2Ffg1kcpr06ktkimrac1hq.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%2Ffg1kcpr06ktkimrac1hq.png" alt="Image showing the download page of vscode" width="800" height="353"&gt;&lt;/a&gt;&lt;br&gt;
select your preferred OS, bit and hit download. &lt;br&gt;
Hurray you are just a tap away from your node.js environment. What you are also going to need is..&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Bash:
&lt;/h2&gt;

&lt;p&gt;an application that helps you run command lines on windows environment. It is more better than the standard window command prompt. you can get it installed when you click &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;git-scm.com&lt;/a&gt;&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%2F0803dsu1w3jsidi56z6f.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%2F0803dsu1w3jsidi56z6f.png" alt="Image showing the download page of git bash" width="800" height="356"&gt;&lt;/a&gt;&lt;br&gt;
Great job you've done. One more thing and you are all set. And that would be ..&lt;/p&gt;

&lt;h2&gt;
  
  
  Postman:
&lt;/h2&gt;

&lt;p&gt;this will be used for building and using of your APIs. You will be using this to make requests to your API. Their are a number of things you can do with the Postman such as, creating collections, creating specific environments, send headers and body data.&lt;br&gt;
It's really a great tool for API development. You can get this installed to your device from &lt;a href="https://www.postman.com/downloads/" rel="noopener noreferrer"&gt;postman.com&lt;/a&gt;&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%2F2wntsqsoad6si57farjn.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%2F2wntsqsoad6si57farjn.png" alt="Image description" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;with these running on your windows PC you are all set and ready for your API development with Node.js.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>learning</category>
      <category>node</category>
    </item>
  </channel>
</rss>
