I have a static site, any way to implement lazy loading of images?
born2run
11:51 pm on Dec 10, 2020 (gmt 0)
Hi so I have a static website. There are many images on the pages. Is there any good way to implement lazy loading of images on all pages of the site, especially for mobile visitors? Some advice would be appreciated much! Thanks!
not2easy
12:24 am on Dec 11, 2020 (gmt 0)
You could add
loading="lazy"
to any images below the fold. As in
<img src="/images/somepicture.jpg" alt="an unusual picture of a thing" loading="lazy">
tangor
5:23 pm on Dec 11, 2020 (gmt 0)
Thanks! Sometimes the obvious just isn't obvious!
robzilla
8:37 pm on Dec 11, 2020 (gmt 0)
Browser support is pretty good already, for an attribute less than 2 years old: [caniuse.com...]
born2run
5:02 am on Dec 12, 2020 (gmt 0)
Hey I am looking at this js script Lozad. In the instructions it says:
All you need to do now is just instantiate Lozad as follows: const observer = lozad(); // lazy loads elements with default selector as '.lozad' observer.observe();
So does that mean I place the above commands into <script>code</script> in my html file? Thanks!
not2easy
5:20 am on Dec 12, 2020 (gmt 0)
If you wish to use a script, I'd suggest you get instructions from the folks with the script. I thought you were just asking how to lazy load images. That method looks a lot more problematic than using browser instructions.
born2run
5:24 am on Dec 12, 2020 (gmt 0)
not2easy that attribute is not supported by Safari in IOS 14.. so that's not good for me.
not2easy
12:44 pm on Dec 12, 2020 (gmt 0)
The images are loaded anyway, it does not break anything. The fact that they will not be delayed on Safari 14 does not change anything for those visitors. Lazy loading the images still loads everything, just loads them after other resources when possible.
If you prefer to use a script to do the same thing, be aware that the script can only be effective after loading the script itself which is one more resource to slow down the loading of the images.
born2run
11:57 pm on Dec 19, 2020 (gmt 0)
not2easy is this tag compatible with Chrome for Android and Chrome for IOS / Mac? Thanks!
not2easy
12:18 am on Dec 20, 2020 (gmt 0)
A few days ago robzilla posted the link to caniuse that shows you what it is and is not compatible with. Here is a copy: [caniuse.com...]
Swanny007
6:44 pm on Dec 23, 2020 (gmt 0)
I believe within the next 2 years lazy loading images will be all done by the browser, no need for developer to do anything. I wish it was here in all browsers already because really it's a client-side thing!
born2run
6:53 pm on Dec 23, 2020 (gmt 0)
So this attribute loading="lazy" will not mess image loading if the browser doesn't support it? Thanks!
buckworks
7:29 pm on Dec 23, 2020 (gmt 0)
A browser that doesn't support loading="lazy" will just ignore it and those users will get whatever they'd have experienced without it.
I've started adding it to every image I can, as browser support is certain to get better and better.
tangor
5:42 am on Dec 24, 2020 (gmt 0)
I've started adding it to every image I can, as browser support is certain to get better and better.
As an ordinary, much like alt="", from this point on I am including as well. Can't hurt, might help, won't break anything.