Home > front end >  React application peformance
React application peformance

Time:06-29

We have a very large application and it takes around 3-4 seconds to load the 3.5 mb javascript bundle. The bundle consists of all the javascript and react code in the application.

We want to reduce the load time to around 1-2 seconds. We tried serving the js through CDN and that takes around 1 second but then all the test stages we have will be served through CDN and not the code changes which the developers make.

We checked but have not tried code splitting using lazy-suspense, bundle splitting and route based slitting. Any suggestions here?

Just wanted to know how we can reduce the performance to this extent. Any help is appreciated.

CodePudding user response:

There's a lot you can do here.

  1. I've had success with route-based code splitting using React.lazy. If your app has a login, lazy-loading the post-login routes might be a good place to start.

  2. Have a good look at your dependencies. There's a strong likelihood that some are very large. For example, if you work with Moment.js, Day.js is much smaller and largely API compatible. (Moment Project Status has some other recommendations).

  3. Check whether you still need all of your dependencies. e.g. dropping support for Internet Explorer and older versions of Safari/Chrome/Firefox might mean you don't need so many polyfills etc.

  4. If things are getting really bad, look into a framework which renders on the server, then (optionally) becomes an SPA (e.g. Remix or Next).

CodePudding user response:

Try to use the useMemo hook for some of your code.

  • Related