Angular应用程序大约需要30秒才能在PCF上加载主页

时间:2019-05-19 09:04:48

标签: angular angular-cli pivotal-cloud-foundry

我正在使用Angular应用(在Angular 7上)。该应用程序包含约15-20个组件,以及模块的延迟加载。

但是,运行ng build --prod后, main.js的大小约为1.27MB

ng build --prod results

该应用程序托管在PCF上。加载主页大约需要30秒钟,而本地加载只需2秒钟。

network stats

  

angular.json配置:

 "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true,
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "2mb",
              "maximumError": "5mb"
            }
          ]
        }
  

package.json

{
  "name": "bbc2023",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --aot",
    "build": "ng build --prod --aot",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build-ie-polyfills": "webpack-cli src/ie-polyfills.js -o src/generated/ie-polyfills.min.js -c webpack-polyfill.config.js",
    "postbuild": "cp -p src/generated/ie-polyfills.min.js dist/generated"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.5",
    "@angular/animation": "^4.0.0-beta.8",
    "@angular/animations": "^7.2.1",
    "@angular/cdk": "^7.3.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^7.3.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@types/socket.io": "^2.1.2",
    "angular-bootstrap-md": "^7.3.0",
    "angular-font-awesome": "^3.1.2",
    "angular2-moment": "^1.9.0",
    "bootstrap": "^4.1.1",
    "chart.js": "^2.7.3",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.4",
    "express": "^4.16.4",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jw-angular-social-buttons": "^1.0.0",
    "mdbootstrap": "^4.6.1",
    "ng-feedback": "^1.1.8",
    "ng2-file-upload": "^1.3.0",
    "ng2-pdf-viewer": "^5.2.3",
    "ngx-bootstrap": "^3.1.4",
    "ngx-lightbox": "^1.2.0",
    "rxjs": "~6.3.3",
    "sockjs-client": "^1.3.0",
    "stompjs": "^2.3.3",
    "tslib": "^1.9.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.12.0",
    "@angular/cli": "~7.2.1",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/googlemaps": "^3.30.16",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "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"
  }
}
  

App.module.ts

@NgModule({
  declarations: [
    AppComponent,LayoutComponent,FooterComponent, HomeComponent
  ],
  imports: [
    CarouselModule,
    AppRoutesModule,
    BrowserModule,
    MatToolbarModule,
    MatSidenavModule,
    MatListModule,
    BrowserAnimationsModule,
    BrowserModule,
    HttpClientModule,
    AngularFontAwesomeModule ,
    MDBBootstrapModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

注意::资产文件夹约为3 MB。我正在努力减小图像大小,但我很好奇也知道如何减小main.js。

请建议是否有减小main.js大小的方法,或者是否有其他方法可以提高性能。

1 个答案:

答案 0 :(得分:0)

您可以从后端压缩main.js和其他js文件

例如在node.js中,您可以使用压缩模块,该模块也可以压缩js文件和标头

压缩https://github.com/expressjs/compression

如果您正在使用webpack和其他模块分析器来查看吃了1.27 mb的东西,也可以使用webpack分析器。