1

When I click on the menu item it takes too much time to load

This is my app-routing-modules.ts

const routes: Routes = [
  {
    path: '',
    children: [
      {
        path: 'login',
        loadChildren: () => import('./pages/login/login.module').then(m => m.LoginModule)
      },
      {
        path: 'products',
        loadChildren: () => import('./pages/products/products.module').then(m => m.ProductsModule)
      },
      {
        path: 'retailer-home',
        loadChildren: () => import('./pages/retailer-home/retailer-home.module').then(m => m.RetailerHomeModule)
      },
   ]
  }
];

This is my product-routing-module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ProductsComponent } from './products.component';

const routes: Routes = [
  { path: '', component: ProductsComponent }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class ProductsRoutingModule {}

First time when I clicked on the menu it took too much time to load.

This is Network tab

enter image description here

1 Answer 1

0

Since you are using lazy loading the js files are fetched only when the route is accessed, maybe that is the cause of the delay, one common way to speed up this, is to preload all the modules, so that as the website loads, the modules are preloaded in the background and may lessen this effect of waiting!

Preloading article

import { NgModule } from '@angular/core';
import {Routes, RouterModule, PreloadAllModules} from '@angular/router';

@NgModule({
  imports: [RouterModule.forChild(routes, {
      preloadingStrategy: PreloadAllModules // <-changed here!
  })],
  exports: [RouterModule],
})
export class AppRoutingModule {}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.