<?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 Ahmed Rebai on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Rebai on Medium]]></description>
        <link>https://medium.com/@rebaiahmed1995?source=rss-6d9352bab9e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GbpcgeF4HyZYHxi9.jpg</url>
            <title>Stories by Ahmed Rebai on Medium</title>
            <link>https://medium.com/@rebaiahmed1995?source=rss-6d9352bab9e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:04:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rebaiahmed1995/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[Boost up your Angular application performance]]></title>
            <link>https://medium.com/@rebaiahmed1995/boost-up-your-angular-application-performance-6df0115d2fea?source=rss-6d9352bab9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6df0115d2fea</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Ahmed Rebai]]></dc:creator>
            <pubDate>Sun, 29 Dec 2019 17:00:07 GMT</pubDate>
            <atom:updated>2019-12-31T22:06:55.294Z</atom:updated>
            <content:encoded><![CDATA[<p>For this tutorial, I have created an Angular app to which I have added Angular Material.</p><p>To begin with, I would like to show you the size of the application running blank without any component or import into the module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*No2613bwKQi0VTMverDhLw.png" /><figcaption><strong>Fig. 1: </strong>Blank Angular app with Angular material vendor size</figcaption></figure><p>As you can see in <strong>Fig. 1</strong>, the vendor size is now 4.1 MB.</p><h3>Rule n°1: Pay attention to imports</h3><p>Let’s suppose you’re using Angular Material, and you needed the button module. You’re going to import MatButtonModule under the module you are working on. By default, the IDE suggests an import for you: import { MatButtonModule } from &#39;@angular/material&#39; .</p><p>It works perfectly fine, but let’s take a look at the size of the vendor now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*Y0qLRK0ixuJ_a3Ha7uonDw.png" /><figcaption><strong>Fig. 2: </strong>Impo MatButtonModule from @angular/material</figcaption></figure><p>As you can see in <strong>Fig. 2</strong>, the vendor size is now 7.09 MB!</p><p>Imagine you’re using only the MatButton, what you did here is you imported all the Angular Material modules and picked the MatButtonModule from it.</p><p>I would recommend paying attention to your imports and replacing that import by import { MatButtonModule } from &#39;@angular/material/button&#39; .</p><p>Let’s see the vendor size if we replace that import.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*snw7taf2xIVhqnu5xJF41Q.png" /><figcaption><strong>Fig. 3: </strong>Import MatButtonModule from @angular/material/button</figcaption></figure><p>As you can see in <strong>Fig. 3</strong>, almost 2.7 MB were saved just by changing a simple import.</p><h3>Rule n°2: Use Lazy Loaded Modules</h3><p>Lazy loaded modules enhance your app performance since you only load the modules needed at a time.</p><p>Adding a new lazy-loaded module will preserve the app vendor size and add a new vendor for the newly added module.</p><p>For example, I’ve added BooksModule as a lazy-loaded module in my app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*vScWdFMcUkS3kwyNe6LCeg.png" /><figcaption><strong>Fig. 4:</strong> Added one lazy-loaded module.</figcaption></figure><p>As you can see in <strong>Fig. 4</strong>, the vendor size is the same as before and we have a new file for the books module.</p><p>To understand how lazy-loaded modules enhance your global app performance, I am going to show the network activity for the route /.</p><figure><img alt="Before loading the Books Module." src="https://cdn-images-1.medium.com/max/1024/1*0izXAmGFRyrzSBMYZPEQ8A.png" /><figcaption><strong>Fig. 5:</strong> Network activity before loading the Books Module.</figcaption></figure><p>As you can see in <strong>Fig. 5</strong>, we haven’t loaded the Books Module by navigating to the root route. But, if we choose to navigate to ‘/books’, here’s what happens then.</p><figure><img alt="Loading the Books Module." src="https://cdn-images-1.medium.com/max/1024/1*VJUP3ZxKFo7b3cJe1F4dCA.png" /><figcaption><strong>Fig. 6:</strong> Network activity while loading the Books Module.</figcaption></figure><p>As you can see in <strong>Fig. 6</strong>, the books-books-module was loaded on demand. This means that every lazy-loaded module is explicitly loaded on demand instead of being loaded on the application launch.</p><h3>Rule n°3: Use gzipper for production servers.</h3><p>Production servers can load compressed files instead of raw ones whenever available. You just need to configure them first in order to enable compression.</p><p>Here, I’m just showing you how to use ‘gzipper’ npm dependency to compress your Angular application and make it production-ready.</p><p>First, you need to install ‘gzipper’ globally by executing the following command: npm i gzipper -g .</p><p>Then, build your app using the following command: ng build --prod &amp;&amp; gzipper --verbose ./dist .</p><p>Here is the result of this command for the current app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*caZSlDFUUSgwEfxCD-jDsw.png" /><figcaption><strong>Fig. 7:</strong> Use of Gzipper</figcaption></figure><p>As you can see in <strong>Fig. 7</strong>, the compressed vendor size is only <em>96KB</em> compared to <em>363KB</em> before compression. It’s been reduced by <strong>74%</strong>.</p><p>After compressing all the files, you just need to copy the content of the dist folder under your server and you’re ready to go.</p><h3>Conclusion</h3><p>I hope you liked this tutorial and found it useful. I tried highlighting the main optimizations possible for an Angular application. If you have any suggestions or questions don’t hesitate to contact me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6df0115d2fea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>