Angular 6 Really Long Time to Refresh

2019-06-02 21:14发布

问题:

I have a problem with my app and refresh.

I am using angular-cli 6 for building my app, and I am using iis for the server.

When I run 'ng build --watch', and I refresh my browser, I have 10 seconds waiting before the app is displaying.

In the Chrome debugger, in performance, I have 8 seconds in "Scripting".

My package.json:

  {
      "name": "front",
      "version": "0.0.0",
      "license": "MIT",
      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build --watch",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "prod": "ng build --prod --aot"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "5.2.1",
        "@angular/cdk": "5.2.1",
        "@angular/common": "^5.2.1",
        "@angular/core": "^5.2.1",
        "@angular/flex-layout": "5.0.0-beta.13",
        "@angular/forms": "5.2.1",
        "@angular/http": "5.2.1",
        "@angular/material": "5.2.1",
        "@angular/platform-browser": "5.2.1",
        "@angular/platform-browser-dynamic": "5.2.1",
        "@angular/router": "5.2.1",
        "angular-calendar": "^0.22.3",
        "angular-draggable-droppable": "^3.0.1",
        "angular-moment-timezone": "1.7.1",
        "bootstrap": "^3.3.7",
        "core-js": "^2.5.3",
        "date-fns": "^1.29.0",
        "hammerjs": "^2.0.8",
        "jquery": "^3.3.1",
        "material-design-icons": "^3.0.1",
        "moment": "^2.20.1",
        "rxjs": "^5.5.6",
        "zone.js": "^0.8.20"  
      },
      "devDependencies": {
        "postcss-custom-properties": "^7.0.0",
        "node-sass": "^4.9.3",
        "@angular/compiler": "^5.2.1",
        "@angular-devkit/build-angular": "^0.7.5",
        "@angular-devkit/core": "0.3.2",
        "@angular/cli": "^6.1.1",
        "@angular/compiler-cli": "^5.2.1",
        "@angular/language-service": "^5.2.1",
        "@angular/material-moment-adapter": "5.2.1",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/node": "^6.0.96",
        "autoprefixer": "^7.2.3",
        "circular-dependency-plugin": "^4.2.1",
        "clean-webpack-plugin": "^0.1.19",
        "codelyzer": "^4.1.0",
        "copy-webpack-plugin": "~4.4.1",
        "cssnano": "^3.10.0",
        "file-loader": "^1.1.5",
        "html-webpack-plugin": "^2.29.0",
        "istanbul-instrumenter-loader": "^3.0.0",
        "jasmine-core": "~2.6.2",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "less-loader": "^4.0.5",
        "postcss-import": "^11.0.0",
        "postcss-loader": "^2.0.10",
        "postcss-url": "^7.1.2",
        "protractor": "~5.1.2",
        "raw-loader": "^0.5.1",
        "sass-loader": "^6.0.6",
        "source-map-loader": "^0.2.0",
        "style-loader": "^0.19.1",
        "stylus-loader": "^3.0.1",
        "ts-node": "~3.2.0",
        "tslint": "~5.7.0",
        "typescript": "2.6.2",
        "uglifyjs-webpack-plugin": "^1.1.8",
        "url-loader": "^0.6.2"
      },
      "peerDependency": {
        "angular-calendar": "^0.22.3"
      }
    }

回答1:

Similar issue:

I used the --poll option

Example:

--poll 5000 for 5 seconds

In headless mode/ no GUI (which is faster)

ng test --no-progress --browsers=ChromeHeadlessCI --code-coverage --poll 5000

Hope that helps.