Using Virtual Scroll for huge lists
There might be certain scenarios in your application where you might have to show a huge set of items. This could be from either your backend API or the browser's local storage. In either case, rendering a lot of items at once causes performance issues because the Document Object Model (DOM) struggles, and also because of the fact that the JS thread gets blocked and the page becomes unresponsive. In this recipe, we'll render a list of 10,000 users and will use the Virtual Scroll functionality from the Angular CDK to improve the rendering performance.
Getting ready
The project that we are going to work with resides in chapter09/start_here/using-cdk-virtual-scroll
, inside the cloned repository. Proceed as follows:
- Open the project in Visual Studio Code (VS Code).
- Open the terminal and run
npm install
to install the dependencies of the project. - Once done, run
ng serve -o
.This should open the app in a new browser tab...