justinribeiro / lite-youtube

The fastest little YouTube web component on this side of the internet. The shadow dom web component version of Paul's lite-youtube-embed.
https://www.npmjs.com/package/@justinribeiro/lite-youtube
MIT License
966 stars 70 forks source link

Lazy or Eager loading #42

Closed andreapernici closed 2 years ago

andreapernici commented 2 years ago

Is it possible to introduce a new parameter to decide if the preview image should be loaded with loading=lazy or loading=eager?

andreapernici commented 2 years ago

Line 56 added


    get loading() {
        return this.getAttribute('loading') || 'lazy';
    }
    set loading(name) {
        this.setAttribute('loading', name);
    }

then added

    initImagePlaceholder() {
        ....
        this.domRefImg.fallback.setAttribute('loading', `${this.loading}`);
        ....
    }

looks like it works.

justinribeiro commented 2 years ago

I can add posterloading, since this would only effect the image poster (and not the default iframe behavior).

justinribeiro commented 2 years ago

Added with 66e87517acb09f48a8387124b0e8cb21b00e940a, will be in v1.3 end of week.

andreapernici commented 2 years ago

Thanks Justin