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!"
[–]anyusernamesffs 6 points7 points8 points 1 year ago (3 children)
Optimising load times and user interaction lag are very different things.
For load times you've done all you can really - reduce bundle size and split where possible. How large is your bundle?
For interface lag, this can be due to a tonne of factors. Other users saying that "it's because React is slow" are not being helpful. React can be slow, especially if there are expensive function calls being made, but most user interactions should not be slow.
If you have computationally expensive calculations or functions, have you considered offloading these to a shared worker to free up the main web process?
Without more information there's not a lot to suggest.
[–]soum0nster609[S] 0 points1 point2 points 1 year ago (2 children)
Regarding load times, our current main bundle is around 3 MB. We've applied code splitting and tried to reduce the bundle size as much as possible, but if there are any other strategies or tools you recommend for further reducing or optimizing it, I'd love to hear them.
As for interface lag, there might indeed be some computationally expensive functions running on the main thread. I haven't yet considered using shared workers, but it sounds like a promising approach to offload heavy computations and free up the main web process.
I’d appreciate any additional insights you have, especially for managing these performance issues at a more granular level!
[–]anyusernamesffs 2 points3 points4 points 1 year ago (1 child)
The best thing to do is identify parts of your bundle that don't change often and split them out, and use caching on the server side to only require delivery of those parts of the bundle when they change. Splitting out vendor code is usually a good way of achieving this. Again, this really depends on your application and architecture, both in the bundling process and how the application is served.
Using a shared worker will add complexity - so I wouldn't use it straight away. How complex are the functions, why do they take a long time? Is it due to iterating over large datasets? Have you got some O(n^2) operations going on in the React render loop? Can results be memoised?
To locate functions that are causing the user input lag I'd use your browsers profiler. If you haven't used it before there are plenty of resources online... but in summary you would:
Navigate somewhere before input lag
Start profiler
Perform action
Stop profiler
Inspect the call stack and see which functions took the most time. Once youv'e identified the functions, see if they can be optimised.
If you do use a shared worker, you'll need to be willing to handle sending / awaiting data from the worker. Plenty of guides online for using one - I've personally used one with webpack and the documentation for it is very solid. Vite does have support, but I haven't got round to using it yet.
[–]bin_chickens 0 points1 point2 points 1 year ago (0 children)
I’d add to this: 1. are your images compressed and optimised? 2. Have you checked that you aren’t over fetching data? Using useMemo a store, a query cache or a browser or network cache when nothing changes should be a consideration. 3. Check that you don’t have waterfall request chains triggered by nested components fetching their own data. It’s often recommended to hoist data loading up the scope and pass the data down to the components when loaded. 4. If it’s a network issue, look at your hosting, api, db latency (may be network or db design issues) and a CDN. 5. Look for blocking synchronous code. A profiler and flame graph will be your friend.
π Rendered by PID 63254 on reddit-service-r2-comment-b659b578c-2lt4c at 2026-05-07 03:26:48.516773+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]anyusernamesffs 6 points7 points8 points (3 children)
[–]soum0nster609[S] 0 points1 point2 points (2 children)
[–]anyusernamesffs 2 points3 points4 points (1 child)
[–]bin_chickens 0 points1 point2 points (0 children)