How to Angular 2 to load pages?

We will create an Angular 2 application that will contain about 200 pages. I know that you can be lazy, upload and upload. If a user navigates to a page with lazy loading and then leaves the page, does it free it from memory? How about a preloaded page? Does the page remain from the moment it was preloaded? My concern is that the end user will run out of memory in the browser if they go to too many pages or if the application takes too long to boot.

+4
source share
1 answer

Yes, if by "pages" you mean components, they will be released, and GC can clear ... provided that you do nothing that forces it to hold ... for example, Observable(for example, router...or some service that you wrote )

Look at the hook of the OnDestroylife cycle. Contribute ngOnDestroy(). Put in it console.logto confirm what it called. Here you can detach handlers.

But then again, you are not too lazy to download "pages". You are lazy to load modules . This is the code. After downloading the code, it is not possible to download this code without reloading the AFAIK browser web page. This is a browser / JavaScript limitation, not an Angular limitation. Is that your concern?

, 200 .

+5

Source: https://habr.com/ru/post/1668936/


All Articles