Tim Stieffenhofer
Tim Stieffenhofer

Reputation: 179

Jquery add loading=lazy to all images

I have a bigger webpage and it would take days to add the loading=lazy attribute to all img tags on my site. Is it useful to use something like $('img'). attr('loading', 'lazy') (does this work?) to the site, or will it just make the site more slower?

Upvotes: 1

Views: 1565

Answers (1)

mfranzke
mfranzke

Reputation: 131

It doesn‘t necessarly have the expected effect - if you‘re adding the attributes via JavaScript, the page itself has already been parsed by the browser and their preloading scripts as well and all of those images would be been put to the download queue, as if the attribute wouldn‘t have existed on them.

So I would heavily recommend to add those attributes within the source code itself already.

Upvotes: 2

Related Questions