A
A
analexeev2021-07-18 18:49:55
JavaScript
analexeev, 2021-07-18 18:49:55

Add loading lazy attribute to all images by script. How good is practice?

In the process of scoring points in Google PageSpeed ​​Insights, I wrote a script that automatically adds the loading="lazy" attribute to all pictures on the site.

Not to say that I understand how the DOM is built and, in general, how the page is rendered, and I had a question. Could it be that such a script, on the contrary, will negatively affect the speed of opening pages?

There are few pictures on each page, a maximum of 5-10. From a loading standpoint, it seems to have a really positive impact.

Here, in fact, is the question. Can this be considered good practice?

function lazyimages() {
var attr = 'loading';
var message = 'lazy'
jQuery('img').attr(attr,message);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question