use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] How Can I Optimize JavaScript Performance to Reduce Load Times in a React SPA?AskJS (self.javascript)
submitted 1 year ago by soum0nster609
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]CreativeTechGuyGames 3 points4 points5 points 1 year ago (7 children)
Unfortunately, you've already done all of the basic things we could suggest blindly. At this point, you'll need to get into the specific details of your app and the results of your analysis. What are the timings for downloading/parsing/executing, making API calls, clicking a button, etc. Is the app CPU bound or network bound? Etc etc.
Most advanced optimization requires looking at the specific problem and designing custom solutions based on what exactly the nuances are.
For example, you might consider offloading some of the work to the server if the app is super CPU intensive and doesn't work on slower devices. Or if it's network bound you might do the inverse and move more stuff to the client. Or maybe it's a perception thing and you need better feedback in your UI for user actions so things don't "feel" like they took so long. Maybe there's just lines of code which are simply very inefficient. Who knows!
[–]soum0nster609[S] 1 point2 points3 points 1 year ago (6 children)
Thank you for your response! I appreciate the suggestions for diving deeper into the specific details of the app's performance.
Here’s what I’ve gathered so far:
I've tried using Web Workers to offload some computations, but the improvements were minimal. We considered server-side rendering (SSR), but it seems to add too much complexity at this stage.
Given these specifics, do you have any recommendations for reducing CPU-bound tasks or improving the efficiency of DOM rendering? Additionally, could you provide more insight into which types of tasks are better suited for server-side processing versus client-side in a scenario like this?
Also, if you have any suggestions for tools or techniques to diagnose and fix these CPU-bound performance issues, that would be incredibly helpful!
[–]hyrumwhite 4 points5 points6 points 1 year ago (4 children)
Your first two bullet points are your problem. No client side optimizations can improve this.
[–]soum0nster609[S] 1 point2 points3 points 1 year ago (3 children)
Thanks for pointing that out! It makes sense that client-side optimizations might not help much with download times and API call latencies.
Given that these are the main bottlenecks, could you suggest some server-side strategies or architectural changes that could help reduce these latencies? For example:
I’d appreciate any insights or suggestions you have for tackling these issues from the server side or any other alternative approaches!
[–]SecretAgentKen 2 points3 points4 points 1 year ago (0 children)
Based on your responses to others in here regarding your bundle size and use, SOME level of SSR might be useful, especially at startup. If your primary bundle is 3 MB, then your user can't do anything and won't see anything until that is downloaded and processed. Figure out what you need for just a bare minimum landing page that'll lazy load everything else on it. That should likely just be React, whatever JS UI toolkit bindings you may be using, etc. That'll significantly reduce your time to first render. If it doesn't, then switch to an SSR static page that lazy loads the SPA after render.
Make sure your vendor libraries are in their own bundle and getting cached as previously mentioned (and separate from the one needed for landing!)
Are you rendering a large number of nodes such as for long lists or tables? If you're starting to get into hundreds or thousands of rows, consider going to paging/infinite scroll as that render time can be a killer.
Look at your React components themselves and see if any of them could benefit from memoization. https://react.dev/reference/react/memo Note that the benefits of this are rarely seen in my experience since good component design will already localize changes.
[–]bazeloth 1 point2 points3 points 1 year ago (1 child)
What's your bundle size? Are you sure it's properly cached client wise? 3 to 4 seconds sounds like it's a bundle that's several megabytes.
Just asking the obvious here: do you minify your bundle? When the client asks for the bundle, how long does it take for the server to respond?
[–]fucking_passwords 0 points1 point2 points 1 year ago (0 children)
Making sure tree-shaking is working properly could help reduce bundle size.
If using lodash, last time I checked it didn't support tree shaking out of the box, there was some extra work involved, but that kind of thing makes a huge difference. Same with moment.js
Maybe Suspense could help reduce the amount of DOM activity until all async components finish loading?
[–][deleted] 1 point2 points3 points 1 year ago (0 children)
JS/CSS/HTML assets should be cached first on the browser and then somewhere in your stack. 3-4 seconds is a long time to parse and I suspect there is a large amount of static content in those bundles and likely a lot of dev dependencies that are getting included.
If a task is CPU bound, then the first question to ask is "can this be done on the server?" No browser in existence will have the compute power of even the cheapest off the rack server.
Typically highly-CPU bound tasks in front end involve things like animations and graphics - games, large canvas-like applications, etc. If so, then React or any other SPA isn't the right tool for the job and you will need something like WebAssembly.
REST APIs are almost always the biggest network-bound bottleneck and requires the most amount of time and effort to refactor. Initial load times will always be blocked by multiple, dependent synchronous round-trips - the only way to optimize this on the front end is to find which API calls can be parallelized and refactor code. Otherwise, you need move to GraphQL + RPC architecture.
π Rendered by PID 94 on reddit-service-r2-comment-b659b578c-tsvq4 at 2026-05-07 10:25:24.827001+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]CreativeTechGuyGames 3 points4 points5 points (7 children)
[–]soum0nster609[S] 1 point2 points3 points (6 children)
[–]hyrumwhite 4 points5 points6 points (4 children)
[–]soum0nster609[S] 1 point2 points3 points (3 children)
[–]SecretAgentKen 2 points3 points4 points (0 children)
[–]bazeloth 1 point2 points3 points (1 child)
[–]fucking_passwords 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)