Created
August 25, 2020 11:59
-
-
Save NetanelBasal/5f344e1ef710d941a3340ef56fb61847 to your computer and use it in GitHub Desktop.
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
import { Directive, ElementRef } from '@angular/core'; | |
@Directive({ selector: 'img' }) | |
export class LazyImgDirective { | |
constructor({ nativeElement }: ElementRef<HTMLImageElement>) { | |
const supports = 'loading' in HTMLImageElement.prototype; | |
if (supports) { | |
nativeElement.setAttribute('loading', 'lazy'); | |
} else { | |
// fallback to IntersectionObserver | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment