Navigating the source-map-explorer tool in a ReactJs environment has left me feeling perplexed

I am facing an issue with my React project where the production build size of the main.xxxx.js file is too large (19.3 MB) and I need to reduce it.

After researching online, I found out that analyzing the build files is the first step to identify the code contributing to the size, so I decided to use source-map-explorer.

This is what I discovered from the analysis (relevant section cropped for clarity):

https://i.stack.imgur.com/k2RW7.png

Surprisingly, the objectWithoutPropertiesLoose.js file makes up 86% of the build size. However, upon checking the file in the node_modules folder, it's only 1KB in size with minimal content:

export default function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;

  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }

  return target;
}

Clearly, there seems to be a misunderstanding on my part, so any guidance or pointers would be greatly appreciated. Thank you.

For reference, here is my package.json:

{
  "name": "clientapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": { 
   // List of dependencies
  },
  "scripts": { 
    // List of scripts
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": { 
    // List of dev dependencies
  }
}

Answer №1

Below are a few effective strategies for reducing the size of your Bundle. Before anything else, ensure that you are using a production build.

  1. If you find the source map to be overwhelming, consider utilizing Webpack Analyzer. Identify the larger components and optimize them by using alternative packages or removing unnecessary ones.

  2. Another option is implementing code splitting in your React app with React.lazy(). Learn more about this approach here. Initiate Route-based code splitting as a starting point before expanding further.

  3. Minification is also effective in reducing bundle size. Consider minimizing comments, large variable names, white spaces, etc. Tools like Terser can aid in minifying your code.

  4. We significantly improved loading times by employing compression techniques to reduce bundle size, leading to over 70% reduction in our case. Popular Compression algorithms like Gzip and Brotli are widely recognized and supported across various browsers.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

MaterialUI React components being stacked on top of each other

Currently working on a project with React and MaterialUI. Just about done with the setup, but I've run into an unexpected issue. The problem is that my simple navbar is overlapping the content beneath it. I set up a code sandbox to demonstrate the i ...

Handling type errors with React Typescript MuiAccordion OnChange event handler

I'm a beginner in typescript and seeking advice on defining the type for an event handler. I have a component that utilizes material ui Accordion and triggers the handler from a container. Therefore, I need to specify the type of handleChange in my co ...

Testing using Azure DevOps platform

I am currently testing an API for uploading profile images. The API takes an image file as input and updates the user's profile picture based on authentication. When I tested this API in Postman, it worked perfectly fine. Now, my goal is to run this s ...

Establishing a parameter in the main component

In my current project utilizing react-router and redux, I have the below App component: export default class App extends Component { render() { return ( <div> <Header /> <PageTitle title="Projec ...

Accessing the inputValue of Autocomplete from Material UI using a reference like React.useRef

I am currently working on accessing the value inside the Autocomplete's inputValue. I passed a reference to the Autocomplete as a functional component, but I'm struggling to find a way to access the current value of inputValue in order to determi ...

Adjust the height of the drawer in material-ui

In my current project using react and material-ui, I am facing a simple issue that has me stumped. I am trying to create a drawer with a specific height so that it does not overlap the app bar when opened. Unfortunately, there is no built-in parameter in ...

Next.JS is efficiently compressing images into base64 format, resulting in an empty image

I recently uploaded a pizza.jpg image to Cloudflare Pages and embedded it into a (.jsp file) page. <div className="product_img"> <Image src={'pizza.jpg'} loader={localLoader} alt={'Pizza'} width='300' he ...

Having trouble downloading files in React and Node.js

I need to retrieve a specific file from the uploads folder and download it into my download folder. Both folders are located in the same directory, and the file's name is BasicUserFile-id.jpg. On my second attempt, I tried hardcoding the file name bu ...

Dealing with null JSON objects in ReactJS

When fetching data from the backend using an API, I need to verify if a domain is valid. The challenge arises when the domain is not valid (i.e. it does not exist in the backend), resulting in an empty array [] being returned. To handle this situation, I ...

Issue: Module 'socket.io' not found while attempting to push changes via git

I've been attempting to upload a project onto a dokku server using the command below. git push dokku master However, during the upload process, I encountered the following error: -----> Running pre-flight checks For smoother zero downtime deplo ...

Is it possible to utilize yarn for retrieving packages from an Azure Artifacts repository located on-premises?

Our team utilizes on-prem Azure DevOps Server 2019 for project management. Within the project directory, there is a .yarnrc file with the following content: C:\xyz\tip\ui\EngagementCommon.UI [master ≡ +3 ~1 -1 !]> cat .\.yar ...

Setting MUI input value within a loop using an array value in React JS: A step-by-step guide

Recently, I created a React js demo using React MUI. To handle inputs, I created a separate component called InputText.js for each input field. The issue I encountered is when I tried to use this component to display multiple education fields stored in an ...

Troubleshooting the failure of implementing react hooks useState within a material-ui Tab container

Recently, I have been experimenting with implementing react-hooks useState in material-ui/tabs component. While I have been successful in using the handleChange function, I am eager to explore and master the use of hooks in this scenario. Interestingly, my ...

error - Uncaught ReferenceError: Unable to use 'auth' before initializing

I am currently following an online tutorial on building a WhatsApp clone and I encountered a problem. import "../styles/globals.css"; import { useAuthState } from "react-firebase-hooks/auth"; import { auth, db } from "../f ...

I'm looking to display images in a designated React component using create react app. What is the best way to accomplish

Currently in the process of revamping an older website using react. Making progress, but encountering an issue with a new component where images are not displaying. Strangely, the images appear in the main class but not within the component class. Even whe ...

Background disappears from Tailwind CSS layout

When using h-screen, everything works fine until the datepicker pops up and expands the viewporthttps://i.stack.imgur.com/tKSbW.png How can I make sure that the background still fills the screen, even when a date box is hovered on triggering the date pick ...

Issue encountered: missing photo data during the transfer of an image from ReactJS to MongoDB

When an image is uploaded to my website, it is sent to the backend for storage in MongoDB database. The base64 of the image is uploaded to the database, but occasionally the photo data retrieved can be "false". For example: (3) [{…}, {…}, {…}] 0 : p ...

Tips on adjusting font size of material ui badge text in reactjs?

I am attempting to adjust the font size of the label within a material ui badge. The current method I am using, style={{ fontSize: "15" }}, only impacts its child element, which happens to be an icon. Sample Code: <Badge badgeContent={props.c ...

Optimizing Firebase and Next.js for serverless deployment on Google Cloud Platform: A guide to effectively managing staging, production, and

Currently, I am utilizing React along with next.js and Google Cloud functions to host my application. Additionally, I am integrating firebase into the mix. One pressing issue I am facing pertains to efficiently configuring the staging and production enviro ...

The issue of conflicting dependencies arises between [email protected] and @apollo/[email protected]

I am encountering an issue with @apollo while working on my react project, and I keep receiving the following error: npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @apollo/<a href="/cdn-cgi/l/email-protect ...