Search code examples
javascriptreactjsperformancesingle-page-applicationvirtual-dom

How the ReactJS can manage the browser's RAM/CPU resources?


Today I have a job interview and they asked me a different question. He said in the Single Page Application (SPA) structure the front-end developers should manage the client resources and cleaning up the other process usages (RAM, CPU).

He said when the clients open more pages or send more requests, the client RAM and CPU will use more and in the future theirs browser will crash or this browser will be slowly because the resource usage is more and more and the components will open on each other.

He said there are many methods to handle this problem, and every body have a different solution for solving this problem. I told him I think the Virtual DOM can solve this problem and by default the ReactJS can support this problem.

He approved but I have doubts who my answer was correct. So, is a right method or solution to manage the SPA clients computer resource's (RAM, CPU)?


Solution

  • The browser (client) does not give you the ability to directly access system resources like RAM or CPU hence you can't really control these resources. But traversing the DOM too much and making too many frequent API calls can lead to a less performant web app. React does improve rendering through its virtual dom feature which means the DOM only gets updated when it absolutely needs to. Also caching less changing datasets can reduce the number of API calls you web app has to make. In general try not to render huge data in a single page for data-heavy web apps, always use pagination. also, try not to fetch large data in one API call too.