This is a really simple demonstration on how to implement lazy loading for images with LQIP approach in a D8 project.
- lazysizes will provide all lazy loading functionality.
- Drupal's
image styles
will generate our lqip(low quality image placeholder).
SCSS
as CSS preprocessor.- mappy breakpoints for media rules.
- Create the
lazysizes
library so we can call it only when we need it. - Create an image style that will generate a scaled image with 15px width.
- Override
responsive-image.html.twig
template. - Write a preprocess function for
responsive_image
where we remove defaultsrc
attribute and substitute it withdata-src
or other required bylazysizes
attributes. - Define basic styles for new picture template and add some additional magic for blurry effects and transitions.