<?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[knowmore.tech - Medium]]></title>
        <description><![CDATA[You can find the tech concepts and tips that helps in your coding - Medium]]></description>
        <link>https://medium.com/knowmore-tech?source=rss----9185c318447---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>knowmore.tech - Medium</title>
            <link>https://medium.com/knowmore-tech?source=rss----9185c318447---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 12 Nov 2026 22:08:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/knowmore-tech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Custom Preloading Strategy in Angular]]></title>
            <link>https://medium.com/knowmore-tech/custom-preloading-strategy-in-angular-19b60a6681b9?source=rss----9185c318447---4</link>
            <guid isPermaLink="false">https://medium.com/p/19b60a6681b9</guid>
            <category><![CDATA[preloading-strategy]]></category>
            <category><![CDATA[single-module-preload]]></category>
            <category><![CDATA[angular-preloading]]></category>
            <category><![CDATA[custom-preloading]]></category>
            <category><![CDATA[preloading]]></category>
            <dc:creator><![CDATA[Pradeep]]></dc:creator>
            <pubDate>Tue, 29 Sep 2020 10:56:24 GMT</pubDate>
            <atom:updated>2020-09-29T10:56:24.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVjDChihjiCnrTEvzAGfkA.png" /></figure><p>In our angular, we have the option to preload the modules while page loads using <a href="https://angular.io/guide/lazy-loading-ngmodules"><strong>Preload Strategy</strong></a><strong>.</strong></p><ol><li><strong>PreloadAllModules</strong></li></ol><p>On going simple, with the below code we can preload all modules</p><pre>import { <a href="https://angular.io/api/router/PreloadAllModules">PreloadAllModules</a>, RouterModule } from &#39;@angular/router&#39;;</pre><pre>@NgModule({<br>  imports: [<br>    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })<br>  ],<br>  exports: [RouterModule]<br>})<br>export class AppRoutingModule {}</pre><p>For confirmation, look at the Network tab in <a href="https://developers.google.com/web/tools/chrome-devtools">chrome dev tools</a>.</p><p>Now, you can see all the modules that you have in your app will load in the background once you opened the application.</p><p>2. <strong>Custom Preloading Strategy</strong></p><p>Loading all modules in background is great but what if our app is very big than we need to preload only selected modules.For this case we can use <strong>Custom Preloading Strategy. </strong>Simply we can add <strong><em>preload : true </em></strong>to the route in our routing module.</p><p>In our <strong>Custom Preloading Strategy, </strong>even we can add delay to the modules ie we can tell them to load after some particular time of successful loading of the first module.</p><p>Now lets create a service named as ‘CustomPreloadingService’ , where our logic is placed</p><pre>import { Injectable } from &#39;@angular/core&#39;;</pre><pre>import { PreloadingStrategy, Route } from &#39;@angular/router&#39;;</pre><pre>import { Observable, of, timer } from &#39;rxjs&#39;;</pre><pre>import { flatMap } from &#39;rxjs/operators&#39;;</pre><pre>@Injectable({</pre><pre>providedIn: &#39;root&#39;</pre><pre>})</pre><pre>export class CustomPreloadingService implements PreloadingStrategy {</pre><pre>preload(route: Route, fn: () =&gt; Observable&lt;any&gt;): Observable&lt;any&gt; {</pre><pre>if (route.data &amp;&amp; route.data[&#39;preload&#39;]) {</pre><pre>   const delay: number = route.data[&#39;delay&#39;];</pre><pre>   return timer(delay).pipe(</pre><pre>   flatMap( _ =&gt; {</pre><pre>     return fn() ;</pre><pre>   }));</pre><pre>  } else {</pre><pre>   return of(null);</pre><pre>  }</pre><pre>}</pre><pre>constructor() { }</pre><pre>}</pre><p>Add our service to the app-routing.module.ts</p><pre>import { CustomPreloadingService } from &#39;./custom-preloading.service&#39;;<br></pre><pre>const routes: Routes = [</pre><pre>{ <br>path : &#39;&#39;,<br>loadChildren : () =&gt; import(&#39;./dashboard/dashboard.module&#39;).then(m =&gt; m.DashboardModule)<br>},</pre><pre>{ <br>path : &#39;auth&#39;,<br>data: {preload: true, delay: 5000},<br>loadChildren : () =&gt; import(&#39;./auth/auth.module&#39;).then(m =&gt; m.AuthModule<br>}</pre><pre>@NgModule({</pre><pre>providers: [CustomPreloadingService],</pre><pre>imports: [RouterModule.forRoot(routes, {</pre><pre>initialNavigation: &#39;enabled&#39;,</pre><pre>preloadingStrategy: CustomPreloadingService</pre><pre>})],</pre><pre>exports: [RouterModule]</pre><pre>})</pre><p>We are saying that it should load the module after 5 seconds of successful loading of dashboard module</p><pre>data: {preload: true, delay: 5000}</pre><p>By doing the above things we can preload the specified module.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19b60a6681b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/knowmore-tech/custom-preloading-strategy-in-angular-19b60a6681b9">Custom Preloading Strategy in Angular</a> was originally published in <a href="https://medium.com/knowmore-tech">knowmore.tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular SSR guide]]></title>
            <link>https://medium.com/knowmore-tech/angular-ssr-guide-16a782a2bf2a?source=rss----9185c318447---4</link>
            <guid isPermaLink="false">https://medium.com/p/16a782a2bf2a</guid>
            <category><![CDATA[window-is-not-defined-ssr]]></category>
            <category><![CDATA[angular-ssr]]></category>
            <category><![CDATA[angular-server-side]]></category>
            <category><![CDATA[angular-ssr-guide]]></category>
            <category><![CDATA[ssrs]]></category>
            <dc:creator><![CDATA[Pradeep]]></dc:creator>
            <pubDate>Fri, 25 Sep 2020 14:31:31 GMT</pubDate>
            <atom:updated>2020-09-25T14:31:31.408Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="angular ssr guide" src="https://cdn-images-1.medium.com/max/1024/1*LIJJBxH-pmKeQ4kRCfzQCA.jpeg" /></figure><p><strong>Why we use Angular SSR ?</strong></p><ol><li>Make easy of Search engine optimization (SEO).</li><li>To show first page quickly.</li><li>To improve performance.</li></ol><p><strong>Angular Application to Universal Angular application:</strong></p><ol><li>Install the Node Module</li></ol><p><a href="https://www.npmjs.com/package/@nguniversal/express-engine"><strong><em>ng add @nguniversal/express-engine</em></strong></a></p><p>2. Now you can run your project using following cmds</p><p><strong><em>npm run build:ssr &amp;&amp; npm run serve:ssr</em></strong></p><p>If every thing works fine than you can serve your project in <a href="http://localhost:4000/">http://localhost:4000</a></p><p>If it fails to run than you might get below errors</p><p>&gt; <strong>ERROR ReferenceError: localStorage is not defined</strong></p><p>&gt; <strong>ERROR ReferenceError: window is not defined</strong></p><p>&gt; <strong>ERROR ReferenceError: gtag is not defined</strong></p><ol><li><strong>ERROR ReferenceError: localStorage is not defined</strong></li></ol><p>Install <strong><em>npm install localstorage-polyfill</em></strong></p><p>Add this in server.ts</p><p>import ‘localstorage-polyfill’</p><p>global[‘localStorage’] = localStorage;</p><p>2. <strong>ERROR ReferenceError: window is not defined</strong></p><p><em>// Copy the following content</em></p><p><em>const domino = require(&#39;domino&#39;);</em></p><p><em>const fs = require(&#39;fs&#39;);</em></p><p><em>const path = require(&#39;path&#39;);</em></p><p><em>const template = fs.readFileSync(path.join(&#39;.&#39;, &#39;dist/your-project-directory-name&#39;, &#39;index.html&#39;)).toString();</em></p><p><em>const win = domino.createWindow(template);</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;window&#39;] = win;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;document&#39;] = win.document;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;DOMTokenList&#39;] = win.DOMTokenList;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;Node&#39;] = win.Node;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;Text&#39;] = win.Text;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;HTMLElement&#39;] = win.HTMLElement;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;navigator&#39;] = win.navigator;</em></p><p><em>// tslint:disable-next-line:no-string-literal</em></p><p><em>global[&#39;MutationObserver&#39;] = getMockMutationObserver();</em></p><p><em>function getMockMutationObserver() {</em></p><p><em>return class {</em></p><p><em>observe(node, options) {</em></p><p><em>}</em></p><p><em>disconnect() {</em></p><p><em>}</em></p><p><em>takeRecords() {</em></p><p><em>return [];</em></p><p><em>}</em></p><p><em>};</em></p><p><em>}</em></p><p><em>// ……………….end………….</em></p><p>3. <strong>ERROR ReferenceError: gtag is not defined</strong></p><p>Inject the following service in constructor</p><p><strong><em>@Inject(PLATFORM_ID) private platformId: object</em></strong></p><p>Import missing dependencies</p><p><strong><em>import { Injectable, Inject, PLATFORM_ID } from ‘@angular/core’;</em></strong></p><p>Use the code snippets</p><p><strong><em>if (isPlatformBrowser(this.platformId)) {</em></strong></p><p><strong><em>// your gtag code is here</em></strong></p><p><strong><em>}</em></strong></p><p>Now you can re-build again using <strong><em>npm run build:ssr </em></strong>and than<strong><em> npm run serve:ssr.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a782a2bf2a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/knowmore-tech/angular-ssr-guide-16a782a2bf2a">Angular SSR guide</a> was originally published in <a href="https://medium.com/knowmore-tech">knowmore.tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>