<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Delyan Georgiev on Medium]]></title>
        <description><![CDATA[Stories by Delyan Georgiev on Medium]]></description>
        <link>https://medium.com/@dgeorgiev_8461?source=rss-89e726b60dfd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sfWxXmtjM5eATvgkOPRF1Q.jpeg</url>
            <title>Stories by Delyan Georgiev on Medium</title>
            <link>https://medium.com/@dgeorgiev_8461?source=rss-89e726b60dfd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:37:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dgeorgiev_8461/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Angular Lazy Loading — Simple but effective]]></title>
            <link>https://medium.com/dvt-engineering/angular-lazy-loading-simple-but-effective-f891c288557b?source=rss-89e726b60dfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f891c288557b</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Delyan Georgiev]]></dc:creator>
            <pubDate>Thu, 03 Sep 2020 09:56:43 GMT</pubDate>
            <atom:updated>2020-09-03T09:56:43.802Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular Lazy Loading — Simple, but Effective</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hk_0T_39R87HUOCAbh8k7w.jpeg" /></figure><p>By default, Angular loads all modules as soon as the web application starts up, whether they are needed or not is irrelevant. As an Angular application grows and more modules and components get added, the size of the compiled bundle (HTML, CSS, and Typescript) generated by Angular increases.</p><p>The bundle size gets bigger, and as a direct correlation, the amount of time it takes to load the web application also increases. End-users may not necessarily notice the difference, but, you may want to implement Lazy Loading in your Angular application.</p><h3>What is Lazy Loading</h3><p>Instead of loading the whole compiled bundle, which takes time and network resources, lazy loading allows for the Angular web app to be split into multiple smaller, and manageable chunks. These chunks are then only loaded when needed.</p><h4>Advantages of lazy loading</h4><p><strong><em>Fewer network resources loaded:</em></strong> When a user loads the web app, instead of all resources of that application being downloaded, a module/chunk will be downloaded and rendered based on the content being requested. This is also helpful on mobile devices especially when an end-user could be outside of a Wi-Fi hotspot.</p><p><strong><em>A decrease in loading time: </em></strong>According to a <a href="https://www.thinkwithgoogle.com/marketing-resources/data-measurement/mobile-page-speed-new-industry-benchmarks/">study conducted by Google in 2018</a>, if a page loads between 1 to 3 seconds, the probability of a user leaving the website increases to 32%. Lazy loading a webpage reduces bundle size, allowing for a quicker loading time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*WbyGIQmoeHslkte--0o5SQ.png" /><figcaption>Probability of user leaving a website depending on time</figcaption></figure><h3>Implementing Lazy Loading in Angular</h3><p>To demonstrate lazy-loading, I created a simple Angular project containing three components: about-us, contact-us, and home. The following steps will demonstrate how to create the components as well as their modules.</p><h4>Generating the components</h4><p>Create a component called home. Run this command in your console.</p><p>ng g c home</p><p>Create a contact-us component as well as its module to be used for routing and lazy loading.</p><p>ng g c contact-us</p><p>Creating the contact-us module with routing.</p><p>ng g m contact-us –-routing</p><p>The same thing to be done for the about-us component.</p><p>ng g c about-us</p><p>ng g m about-us –-routing</p><p>The home component will be a runtime loaded component. On the other hand, the two lazily loaded components will be about-us and contact-us.</p><p>Now that we have three empty components, let’s add some basic styling and add routes. Thereafter we are going to create a simple nav-bar that allows us to route to different components.</p><p>In the src/app/app.component.html file, add the following code :</p><p>In the src/app/app.component.scss add the following CSS:</p><p>Go back to your browser, and now we have three links that take us to different components. Now, let’s add some routing so that we can see the components that are loaded when the links in the nav-bar are clicked.</p><p>In the routes array in src/app/app-routing.module.ts, add the following paths. Don’t forget to import the components.</p><h4>About-us component</h4><p>Add the following HTML to src/app/about-us/about-us.component.html</p><p>Now add some styling to the component.</p><p>Now, we add a route in the about-us module which takes us to the about-us component. Make sure to also import your component.</p><p>You should see this as a result if you click on the About link in the nav-bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Bof_eXntwwyxpGaX7M5Qkg.png" /><figcaption>About link is clicked</figcaption></figure><h4>Contact-us component</h4><p>Add the following HTML and styling to src/app/contact-us/</p><p>Now, we add a route in the contact-us module which takes us to the contact-us component. Make sure to also import your component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*7VWX81xEapbVGAx2Z3wauQ.png" /><figcaption>Contact Page is clicked</figcaption></figure><h4>Home component</h4><p>The home component will not be lazy-loaded for demonstration purposes so there is no module for it needed. Add some HTML and styling in src/app/home/</p><p>And finally, you should see this if the home component is loaded correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*8UCZCdWTMR0SfP_ncY-ycw.png" /><figcaption>Home component clicked</figcaption></figure><p>Now, we are not finished yet as these components are not loaded separately when clicked.</p><h4>Let’s add some lazy loading!</h4><p>At the beginning of the tutorial, where we added our routes to the various components, we specified a certain component to be showed once a link is clicked. Now instead of loading a component, we are going to be loading a module that contains routes and paths of a specific component.</p><p>We are going to use a loadChildren property in the path. This property uses an arrow function which is called to resolve and locate a collection of lazy-loaded routes of a specific component. Let’s update the routes array in the app-routing.module.ts file.</p><p>Loading modules with the loadChildren property</p><p>Go back to your browser and click on the home component link. Go to the developer tools, click on the Network tab. You can see that the runtime.js, polyfills.js, styles.js, vendor.js, and main.js files are initially loaded. These are code bundles generated by Angular.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ke820cyAmFKKBb9Cb_ai-A.png" /><figcaption>Home component loaded along with Angular generated files</figcaption></figure><p>Once you click on the About link or the Contact Page link, you will firstly notice that the About component is loaded, but also you will see within the network tab, the About-Us chunk is loaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*B_JLUsmtmokpyPw2WPqJ0A.png" /><figcaption>About-Us chunk generated by Angular is lazily loaded</figcaption></figure><p>Next, click on the Contact Page link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*4SKImODAoQdoZ1KxpURa0g.png" /><figcaption>The second module is loaded once the Contact Page link is clicked</figcaption></figure><p>Now, clicking on the About link again, will not load any module because the module has already been loaded. Notice how small the size of the chunks are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*R5d_HuwCu4orQL7VreFXiA.png" /><figcaption>About-Us module not loaded</figcaption></figure><h3>In conclusion</h3><p>Separating an application into modules/chunks is a good way to improve the loading time of an Angular application, as well as to keep the file size of the application low.</p><p>If you have any problems with the code above, <a href="https://github.com/Delian4o-web/angular-lazy-loading">here</a> is a link to the Github repository which contains the final code.</p><h3>See other resources</h3><p><a href="https://angular.io/guide/lazy-loading-ngmodules">Angular</a></p><p><a href="https://ultimatecourses.com/blog/lazy-load-angular-modules">https://ultimatecourses.com/blog/lazy-load-angular-modules</a></p><p><a href="https://blog.bitsrc.io/boost-angulars-performance-by-lazy-loading-your-modules-ca7abd1e2304">Boost Angular’s Performance by Lazy Loading your Modules</a></p><p>Thanks to <a href="https://medium.com/dvt-engineering">DVT</a> and Mr<a href="https://medium.com/@kennedycsigauke"> Kennedy Sigauke</a>, developer at DVT for the proofreading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f891c288557b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dvt-engineering/angular-lazy-loading-simple-but-effective-f891c288557b">Angular Lazy Loading — Simple but effective</a> was originally published in <a href="https://medium.com/dvt-engineering">DVT Software Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>