-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix image lazy loading for Chrome in SSR mode (#18761)
This PR provides the work around for not working image lazy loading in SSR in Chrome and Safari. Closes: https://jira.tools.sap/browse/CXSPA-6719
- Loading branch information
Showing
1 changed file
with
34 additions
and
24 deletions.
There are no files selected for viewing
58 changes: 34 additions & 24 deletions
58
projects/storefrontlib/shared/components/media/media.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
<picture *ngIf="media?.srcset && !isLegacy; else tmpImg"> | ||
<source | ||
*ngFor=" | ||
let source of media!.srcset! | cxMediaSources; | ||
trackBy: trackByMedia | ||
" | ||
[srcset]="source.srcset" | ||
[media]="source.media" | ||
/> | ||
<ng-container *ngIf="!!media"> | ||
<picture *ngIf="media.srcset && !isLegacy; else legacyImgTmp"> | ||
<source | ||
*ngFor=" | ||
let source of media!.srcset! | cxMediaSources; | ||
trackBy: trackByMedia | ||
" | ||
[srcset]="source.srcset" | ||
[media]="source.media" | ||
/> | ||
|
||
<ng-container [ngTemplateOutlet]="tmpImg"></ng-container> | ||
</picture> | ||
<img | ||
[loading]="loading" | ||
[alt]="media.alt" | ||
[title]="media.alt" | ||
[src]="media.src" | ||
[attr.role]="media.role" | ||
(load)="loadHandler()" | ||
(error)="errorHandler()" | ||
/> | ||
</picture> | ||
|
||
<ng-template #tmpImg> | ||
<img | ||
*ngIf="media && media.src" | ||
[alt]="media.alt" | ||
[title]="media.alt" | ||
[src]="media.src" | ||
[srcset]="media.srcset || media.src" | ||
[attr.role]="media.role" | ||
[loading]="loading" | ||
(load)="loadHandler()" | ||
(error)="errorHandler()" | ||
/> | ||
</ng-template> | ||
<ng-template #legacyImgTmp> | ||
<img | ||
*ngIf="media.src" | ||
[loading]="loading" | ||
[alt]="media.alt" | ||
[title]="media.alt" | ||
[src]="media.src" | ||
[srcset]="media?.srcset || media.src" | ||
[attr.role]="media.role" | ||
(load)="loadHandler()" | ||
(error)="errorHandler()" | ||
/> | ||
</ng-template> | ||
</ng-container> |