-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for lazy loading iframes #447
Comments
I'm not sure this lib is a perfect fit for that use case but maybe it will work if you just create a import { LoadImageProps } from 'ng-lazyload-image';
export function loadImage({ imagePath }: LoadImageProps) {
return [ imagePath ];
}
@NgModule({
declarations: [ AppComponent ],
imports: [
BrowserModule,
LazyLoadImageModule.forRoot({ loadImage })
],
bootstrap: [ AppComponent ]
})
export class MyAppModule {} But I guess you don't want to use that function for all images, but just for some iframes. I believe it is a good idea to be able to add hooks to specific images. |
Also, same request for lazily loading I've now created a Directive for emitting visibility based on IntersectionObserver and can use it as needed but I don't know why this lib wouldn't just support that |
Sorry for my late response.
The problem is that this lib lazyload the image by creating an I have the following questions:
I guess one could solve this by using the following hook, is that : import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
class LazyLoadImageHooks extends IntersectionObserverHooks {
setup(attributes: Attributes) {
if (attributes.element.tagName !== 'IFRAME') {
return super.setup(attributes);
}
}
loadImage(attributes: Attributes) {
if (attributes.element.tagName === 'IFRAME') {
return [attributes.imagePath];
}
return super.loadImage(attributes);
}
}
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, LazyLoadImageModule.forRoot(LazyLoadImageHooks)],
bootstrap: [AppComponent],
})
export class MyAppModule {} |
We've got a dynamically built site via CMS and our clients keep adding iframes containing megabytes of resources onto the homepage. It'd be awesome to be able to lazily load those too.
Tried it initially because both images and iframes have the [src] property but it just tried to load it as an image instead of just adding the property
The text was updated successfully, but these errors were encountered: