Skip to content

Commit

Permalink
feat: Service worker, perf tuning (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender authored Aug 22, 2024
1 parent 8f4d728 commit d9f0246
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 58 deletions.
13 changes: 2 additions & 11 deletions Client/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,9 @@
"with": "src/environments/environment.prod.ts"
}
],
"optimization": {
"styles": {
"minify": true,
"inlineCritical": true
},
"scripts": true,
"fonts": {
"inline": true
}
},
"optimization": true,
"outputHashing": "all",
"sourceMap": true,
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"budgets": [
Expand Down
20 changes: 20 additions & 0 deletions Client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@angular/platform-browser": "18.2.0",
"@angular/platform-browser-dynamic": "18.2.0",
"@angular/router": "18.2.0",
"@angular/service-worker": "18.2.0",
"@ctrl/tinycolor": "4.1.0",
"@ng-matero/extensions": "18.2.0",
"chart.js": "4.4.4",
Expand Down
2 changes: 1 addition & 1 deletion Client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CommonModule } from '@angular/common';

import { MatButtonModule as MatButtonModule } from '@angular/material/button';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatTooltipModule } from '@angular/material/tooltip';
Expand Down
38 changes: 23 additions & 15 deletions Client/src/app/chart/chart.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@ import { ChartComponent } from './chart.component';

import { ChartService } from '../services/chart.service';

@NgModule({ declarations: [
ChartComponent
],
exports: [
ChartComponent
],
bootstrap: [ChartComponent], imports: [CommonModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
MatToolbarModule,
MatTooltipModule], providers: [
ChartService,
provideHttpClient(withInterceptorsFromDi())
] })
@NgModule({
declarations: [
ChartComponent
],
exports: [
ChartComponent
],
bootstrap: [
ChartComponent
],
imports: [
CommonModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
MatToolbarModule,
MatTooltipModule
],
providers: [
ChartService,
provideHttpClient(withInterceptorsFromDi())
]
})
export class ChartModule { }
69 changes: 39 additions & 30 deletions Client/src/app/picker/settings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,43 @@ import { PickConfigComponent } from './pick-config.component';
import { ChartService } from '../services/chart.service';
import { ApiService } from '../services/api.service';

@NgModule({ declarations: [
SettingsComponent,
PickConfigComponent
],
exports: [
SettingsComponent,
PickConfigComponent
],
bootstrap: [], imports: [CommonModule,
FormsModule,
MatBottomSheetModule,
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatListModule,
MatSelectModule,
MatSlideToggleModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
MtxColorpickerModule,
ColorCompactModule], providers: [
ChartService,
ApiService,
{ provide: ErrorStateMatcher, useClass: ShowOnDirtyErrorStateMatcher },
provideHttpClient(withInterceptorsFromDi())
] })
@NgModule({
declarations: [
SettingsComponent,
PickConfigComponent
],
exports: [
SettingsComponent,
PickConfigComponent
],
bootstrap: [],
imports: [
CommonModule,
FormsModule,
MatBottomSheetModule,
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatListModule,
MatSelectModule,
MatSlideToggleModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
MtxColorpickerModule,
ColorCompactModule
],
providers: [
ChartService,
ApiService,
{
provide: ErrorStateMatcher,
useClass: ShowOnDirtyErrorStateMatcher
},
provideHttpClient(withInterceptorsFromDi())
]
})
export class SettingsModule { }
44 changes: 44 additions & 0 deletions Client/src/ngsw-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": "YYYY.MM.DD",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(png|jpg|jpeg|svg)"
]
}
}
],
"dataGroups": [
{
"name": "reference-data",
"urls": [
"https://stock-charts-api.azurewebsites.net/indicators",
"https://localhost:44392/indicators"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 10,
"maxAge": "1h",
"timeout": "10s"
}
}
]
}
8 changes: 7 additions & 1 deletion Server/WebApi/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ public async Task<IActionResult> GetQuotes()

[HttpGet("indicators")]
public IActionResult GetIndicators()
=> Ok(Metadata.IndicatorList($"{Request.Scheme}://{Request.Host}"));
{
Response.Headers.CacheControl = "public, max-age=3600"; // 1 hour TTL
Response.Headers.ETag = "YYYY.MM.DD"; // only changes with deployment
Response.Headers.LastModified = DateTime.UtcNow.ToString("R");

return Ok(Metadata.IndicatorList($"{Request.Scheme}://{Request.Host}"));
}


//////////////////////////////////////////
Expand Down

0 comments on commit d9f0246

Please sign in to comment.