** Main Question: Can I implement lazy loading of a photo when the photos are pulling from a HubDB? **
Why/backstory:
I've just swtiched my team directory over to pulling from a HubDB (for much easier edits), and I'm running into an issue trying to get them to lazy load. Because all of the 115 images are killing my loading time.
The coding below is coding that worked because it wasn't pulling from a HubDB
<style> .grid { display: grid; /* Display as a Grid */ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* repeat = as many times as you can fit */ /* auto-fit = fit as many items on the line as possible, go bigger if you need to */ /*minmax = (min size, max size) = the minimum size the column should be is 200px, but if there's space then give them all 1fr of that width. */ grid-gap: 10px; }
Now, I'm trying to get it work work with my HubDB module, but this is what I'm getting. It starts with the image showing but when you scroll it starts looking like this:
@LaurenO most likely a javascript error. For a simpler solution, you could get rid of the javascript library, revert the image markup back to normal (replace the `data-src` back to just `src`) and add the `loading="lazy"` attribute to your images. This uses the native browser lazy loading functionality that was recently introduced in Chrome. More info here:https://addyosmani.com/blog/lazy-loading/
Example image:
<img src="example.com" loading="lazy">
It makes lazy loading super simple and quick but the only downside is it doesn't yet work in all major browsers.
@LaurenO most likely a javascript error. For a simpler solution, you could get rid of the javascript library, revert the image markup back to normal (replace the `data-src` back to just `src`) and add the `loading="lazy"` attribute to your images. This uses the native browser lazy loading functionality that was recently introduced in Chrome. More info here:https://addyosmani.com/blog/lazy-loading/
Example image:
<img src="example.com" loading="lazy">
It makes lazy loading super simple and quick but the only downside is it doesn't yet work in all major browsers.
@stefen That does seem like the easiest solution! Lighthouse liked the page more especially with the time to interactive. I hope this gets supported on all the browsers pretty soon.