<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>angular | Ash Grennan</title><link>https://www.ashgrennan.com/tag/angular/</link><atom:link href="https://www.ashgrennan.com/tag/angular/index.xml" rel="self" type="application/rss+xml"/><description>angular</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><copyright>Copyright 2021 Ash Grennan | Information provided is published and reviewed according to the latest literature and is for general information purpose only</copyright><lastBuildDate>Sun, 22 Dec 2019 00:00:00 +0000</lastBuildDate><image><url>https://www.ashgrennan.com/media/icon_hu11c635150b33d0b2d171d7f02d87fa59_7607_512x512_fill_lanczos_center_3.png</url><title>angular</title><link>https://www.ashgrennan.com/tag/angular/</link></image><item><title>🔃 Angular Network Aware Preload Strategy</title><link>https://www.ashgrennan.com/post/angular-network-aware-preload-strategy/</link><pubDate>Sun, 22 Dec 2019 00:00:00 +0000</pubDate><guid>https://www.ashgrennan.com/post/angular-network-aware-preload-strategy/</guid><description>&lt;h3 id="lazy-loading-routes">Lazy Loading Routes&lt;/h3>
&lt;p>As your app becomes larger, with different modules to group feature components, a common approach is to lazy load
each module in your main routing configuration. Angular recommends this from the start, since it&amp;rsquo;s a simple yet scalable
pattern to load your projects dependencies once the &lt;code>route&lt;/code> is activated.
&lt;escape>&lt;!-- more -->&lt;/escape>
You have likely seen or implemented this pattern in the &lt;code>app-routing.module.ts&lt;/code> like below:&lt;/p>
&lt;pre>&lt;code class="language-csharp">import { NgModule } from '@angular/core';
import { RouterModule, Routes }
const routes: Routes = [
{
path: 'index',
loadChildren: 'src/app/modules/home/home.module#HomeModule'
},
{
path: 'shop',
loadChildren: 'src/app/modules/shop/shop.module#ShopModule'
}
];
&lt;/code>&lt;/pre>
&lt;p>or&lt;/p>
&lt;pre>&lt;code class="language-csharp">import { NgModule } from '@angular/core';
import { RouterModule, Routes }
const routes: Routes = [
{
path: 'index',
loadChildren: () =&amp;gt; import('src/app/modules/home/home.module').then(m =&amp;gt; m.HomeModule) }
},
{
path: 'users',
loadChildren: () =&amp;gt; import('src/app/modules/user/user.module').then(m =&amp;gt; m.UserModule) }
}
];
&lt;/code>&lt;/pre>
&lt;p>Note: the second example is new as of Angular 8, and is a &lt;a href="https://caniuse.com/#feat=es6-module-dynamic-import" target="_blank" rel="noopener">widely supported&lt;/a> method of importing modules.&lt;/p>
&lt;p>The above examples allow the module to be loaded in when they&amp;rsquo;re requested via accessing the &lt;code>route&lt;/code> tied to the module.&lt;/p>
&lt;h3 id="eager-loading">Eager Loading&lt;/h3>
&lt;p>The standard method of preloading any specified modules as above is to use the &lt;code>PreloadAllModules&lt;/code> strategy. This quite simple loads all modules that have been specified in our &lt;code>routes&lt;/code> array. The advantage of this method is a better user experience since there isn&amp;rsquo;t any time lag between an end user clicking a route e.g. &lt;code>/users&lt;/code> and the module having to be downloaded.&lt;/p>
&lt;pre>&lt;code class="language-csharp">imports: [
... // omitted for brevity
RouterModule.forRoot(routes,
{ preloadingStrategy: PreloadAllModules })
]
&lt;/code>&lt;/pre></description></item></channel></rss>