ses
ses

Reputation: 13352

angular 7 slow on refresh OR route change

env. ubuntu 16.04 node: v10.15.1 npm:6.4.1

I have two pages in my newly created web app, less, html. no ajax calls.

Here is my package.json

{
  "name": "frontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.4",
    "ngx-bootstrap": "^3.2.0",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.1",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

in chrome debug, I do not see any delays, all loads in 2-3 ms. but in fact it takes 2-3-4 seconds to refresh.

This is how I defined the routes.

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import {AppComponent} from './app.component';
import {RegisterForm1Component} from './components/register/register-form1.component';
import {MembershipComponent} from './domain/membership.component';

const routes: Routes = [
  { path: '', redirectTo: '/login', pathMatch: 'full' },
  { path: '', redirectTo: '/register', pathMatch: 'full' },
  { path: 'login', component: MembershipComponent },
  { path: 'register', component: RegisterForm1Component }
];

@NgModule({
  declarations: [],
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule {


}

Any idea?

Upvotes: 2

Views: 4599

Answers (1)

Ivan
Ivan

Reputation: 1577

I don't see any faults in your config. But you can improve the performance of your app:

  • Check you always use Angular routing instead of fully reloading your app on every new route.

    Use `<a [routerLink]="[url]">` and `this.router.navigate([url]);`
    
  • You can increase the scripting time of your app by using AOT compilation

  • You can decrease bundle size by splitting your app on chunks (lazy loading) and Uglifying them

Upvotes: 3

Related Questions