{"id":12995,"date":"2020-05-26T09:34:30","date_gmt":"2020-05-26T09:34:30","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/blog\/?p=12995"},"modified":"2025-03-10T10:39:29","modified_gmt":"2025-03-10T10:39:29","slug":"implement-angular-lazy-loading","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/blog\/implement-angular-lazy-loading","title":{"rendered":"How to Implement Angular Lazy loading in Existing Application to Make it Faster, Better and Superior Performance?"},"content":{"rendered":"<p>Angular is a great JavaScript framework of modern-day for building interactive components as well as elements. It is widely used for building SPAs and dynamic programming structure. The front-end framework is based on TypeScript with additional features like interfaces, classes, and static typing that encourages component-based development and make sure that components are decoupled as well as conveniently reusable.<\/p>\n<p>Images play a significant role in page-load times, and that\u2019s the reason if you want to improve the performance of Angular web application, lazy-load images come handy and that&#8217;s why you need <strong>angular lazy loading<\/strong> implemention?<\/p>\n<h2>So, let\u2019s start with what is Lazy Loading?<\/h2>\n<p>Lazy loading, also known as on-demand loading, is an optimization technique that delays the loading or elements or components until they are brought into the viewport.<\/p>\n<p>When you log in to\/admin, you will come across a JavaScript code \u2018chunk\u2019 specially designed for the Admin dashboard. Likewise, when you load \/shop, you will get a similar \u201cchunk,\u201d specially written for the Shop! The code is lazy loaded and injected into the browser for the specific use of the Shop module. <\/p>\n<pre>\r\nmain.chunk.js \/\/ loaded everywhere\r\nshop.chunk.js \/\/ lazy module\r\nadmin.chunk.js \/\/ lazy module\r\n<\/pre>\n<p>In a layman\u2019s term, while scrolling any eCommerce website, the bottom images of a page will only be displayed when the user scrolls there.<\/p>\n<h2>Angular Lazy loading, why it needs your special attention and importance?<\/h2>\n<p>It is one of the proven ways to improve the performance of your website.<\/p>\n<ul class=\"bullets\">\n<li><strong>Reduce Page Load Time:<\/strong> Load only requested elements and helps to reduce the amount of data to be loaded.<\/li>\n<li><strong>Conserving Bandwidth:<\/strong>  Helps to save bandwidth from the viewers as well as a web browser. Deliver only required content and refrain from sending unnecessary content. <\/li>\n<li><strong>Save System Resources:<\/strong> Render code only needed. Save memory resources.<\/li>\n<\/ul>\n<h2>How to Implement Lazy Loading in Angular?<\/h2>\n<p>ngx-loadable is a lightweight package for implementing <a href=\"https:\/\/www.bacancytechnology.com\/blog\/lazy-loading-in-angular\" target=\"_blank\" rel=\"noopener\">Angular lazy loading<\/a> components. It contains a simple API to support loading indicators.<\/p>\n<h2>How to Implement ngx-loadable?<\/h2>\n<p><strong>Stap 1.<\/strong> Install ngx-loadable in npm\/yarn and add LoadableModule in your AppModule.<\/p>\n<p><strong>Stap 2.<\/strong> To add a module with a bootstrapped, follow the listed below command using Angular CLI.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/add-a-module-with-a-bootstrapped.png\" alt=\"add a module with a bootstrapped\" width=\"800\" height=\"53\" class=\"alignleft size-full wp-image-12996\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/add-a-module-with-a-bootstrapped.png 800w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/add-a-module-with-a-bootstrapped-300x20.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/add-a-module-with-a-bootstrapped-768x51.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/add-a-module-with-a-bootstrapped-20x1.png 20w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Make sure that module, as well as component names are same.<\/p>\n<p>Adding components in the bootstrap is significant as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/Adding-components.png\" alt=\"Adding components\" width=\"800\" height=\"181\" class=\"alignleft size-full wp-image-12999\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/Adding-components.png 800w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/Adding-components-300x68.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/Adding-components-768x174.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/Adding-components-20x5.png 20w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><br \/>\n<strong>Step 3.<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-3-add.png\" alt=\"step 3 add\" width=\"800\" height=\"220\" class=\"alignleft size-full wp-image-13000\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-3-add.png 800w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-3-add-300x83.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-3-add-768x211.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-3-add-20x6.png 20w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><br \/>\n<strong>Step 4.<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-4-add.png\" alt=\"step 4 add\" width=\"800\" height=\"259\" class=\"alignleft size-full wp-image-13001\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-4-add.png 800w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-4-add-300x97.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-4-add-768x249.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/step-4-add-20x6.png 20w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Hovering on the mouse button, you will find that LoginModal Module is pre-loaded. When clicking shows it is still downloading, then LoginModalComponent loads in the ngx-loadable element.<\/p>\n<p>Configure ngx-loadable using custom paths. Bypassing configuration to the LoadableModule.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/ngx-loadabl.png\" alt=\"ngx-loadabl\" width=\"800\" height=\"199\" class=\"alignleft size-full wp-image-13003\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/ngx-loadabl.png 800w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/ngx-loadabl-300x75.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/ngx-loadabl-768x191.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2020\/05\/ngx-loadabl-20x5.png 20w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Lazy-loading non-routable modules\u2014ngx-loadable is a convenient approach to managing <a href=\"https:\/\/www.bacancytechnology.com\/blog\/lazy-loading-in-angular\" target=\"_blank\" rel=\"noopener\">lazy loading in angular<\/a>.<\/p>\n<p>To boost the performance of your application, I strongly recommend it to optimize it step-by-step, instead of doing it all together in one big step. Once you follow the above steps and if you see a chunk, then you have configured it in the right way.<\/p>\n<p>If you are not sure about how to do it and looking for the experts who can help you <em>implement Angular lazy loading into your existing app<\/em>, then hire Angular developers from us. We are a globally renowned <a href=\"https:\/\/www.bacancytechnology.com\/angular-js-development-company\" rel=\"noopener\" target=\"_blank\">Angular development company<\/a>, offering top-of-the-line Angular development services.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Angular is a great JavaScript framework of modern-day for building interactive components as well as elements. It is widely used for building SPAs and dynamic programming structure. The front-end framework is based on TypeScript with additional features like interfaces, classes, and static typing that encourages component-based development and make sure that components are decoupled as [&hellip;]<\/p>\n","protected":false},"author":146,"featured_media":13023,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[989,1364],"tags":[],"coauthors":[2427],"class_list":["post-12995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angularjs","category-application-development"],"acf":[],"modified_by":"Binal Prajapati","_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/12995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/users\/146"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=12995"}],"version-history":[{"count":0,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/12995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media\/13023"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=12995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=12995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=12995"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/coauthors?post=12995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}