From 80210bd3bf545bc68824e7f8960528df3cd326be Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:05:51 -0700 Subject: [PATCH] Performance: use NgOptimizedImage for thumbnail lazy loading (#13169) --- .../document-card-large/document-card-large.component.html | 2 +- .../document-card-large.component.spec.ts | 6 ++++++ .../document-card-large/document-card-large.component.ts | 3 ++- .../document-card-small/document-card-small.component.html | 2 +- .../document-card-small/document-card-small.component.scss | 6 +++++- .../document-card-small.component.spec.ts | 6 ++++++ .../document-card-small/document-card-small.component.ts | 3 ++- 7 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html index 08d232185..facd0ca27 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html @@ -2,7 +2,7 @@
@if (document()) { - +
diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts index d50bba65f..421754618 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts @@ -88,6 +88,12 @@ describe('DocumentCardLargeComponent', () => { expect(fixture.nativeElement.textContent).toContain('8 pages') }) + it('should lazy load the thumbnail', () => { + const thumbnail: HTMLImageElement = + fixture.nativeElement.querySelector('img.doc-img') + expect(thumbnail.getAttribute('loading')).toEqual('lazy') + }) + it('should trim content', () => { expect(component.contentTrimmed).toHaveLength(503) // includes ... }) diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts index 1dac73959..9304d1168 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts @@ -1,4 +1,4 @@ -import { AsyncPipe } from '@angular/common' +import { AsyncPipe, NgOptimizedImage } from '@angular/common' import { AfterViewInit, Component, @@ -46,6 +46,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading TagComponent, CustomFieldDisplayComponent, AsyncPipe, + NgOptimizedImage, UsernamePipe, CorrespondentNamePipe, DocumentTypeNamePipe, diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html index a7a30c790..7a0a507e6 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html @@ -2,7 +2,7 @@
@if (document()) { - +
diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss index 6f2260e47..9dd7ed5cf 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.scss @@ -22,10 +22,14 @@ } } +.doc-img-container { + position: relative; + height: 180px; +} + .doc-img { object-fit: cover; object-position: top left; - height: 180px; } .document-card-check { diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts index 45b812462..c6127494b 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts @@ -61,6 +61,12 @@ describe('DocumentCardSmallComponent', () => { expect(fixture.nativeElement.textContent).toContain('12 pages') }) + it('should lazy load the thumbnail', () => { + const thumbnail: HTMLImageElement = + fixture.nativeElement.querySelector('img.doc-img') + expect(thumbnail.getAttribute('loading')).toEqual('lazy') + }) + it('should display a document, limit tags to 5', () => { expect(fixture.nativeElement.textContent).toContain('Document 10') expect( diff --git a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts index 1e45b982a..633ad3e2e 100644 --- a/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts +++ b/src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts @@ -1,4 +1,4 @@ -import { AsyncPipe } from '@angular/common' +import { AsyncPipe, NgOptimizedImage } from '@angular/common' import { AfterViewInit, Component, @@ -46,6 +46,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading TagComponent, CustomFieldDisplayComponent, AsyncPipe, + NgOptimizedImage, UsernamePipe, CorrespondentNamePipe, DocumentTypeNamePipe,