我最近使用 Angular 启动了我的网站并使其具有通用性。但是当我在 gtmetrix 上查看这个站点时,它的性能并不好。谁能指导我该怎么做?我大大减小了照片的大小,但对 JavaScript 文件一无所知。
链接Gtmetrix:https ://gtmetrix.com/reports/tarhbama.com/4vp1UBUI/
我总是使用 ng build --prod。我使用 gzipper 文件。
app.module.ts
import { BrowserModule, BrowserTransferStateModule, makeStateKey, TransferState } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { environment } from 'src/environments/environment';
import { ServiceWorkerModule } from '@angular/service-worker';
import { SharedModule } from './shared/shared.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
BrowserAnimationsModule,
BrowserTransferStateModule,
CoreModule,
AppRoutingModule,
SharedModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
应用程序路由.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AuthGuard } from './core/services/auth-guard.service';
import { AdminContentComponent } from './shared/layout/admin-content/admin-content.component';
import { UiContentComponent } from './shared/layout/ui-content/ui-content.component';
const routes: Routes = [
{ path: 'admin', canActivate: [AuthGuard], component: AdminContentComponent, loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule) },
{ path: '', component: UiContentComponent, loadChildren: () => import('./ui/ui.module').then(m => m.UiModule) },
];
@NgModule({
imports: [RouterModule.forRoot(routes, {
initialNavigation: 'enabled',
scrollPositionRestoration: 'enabled',
onSameUrlNavigation: 'reload',
})],
exports: [RouterModule]
})
export class AppRoutingModule { }