This package implements Lazy Loading for Responsive Images from the Sitegeist.Kaleidoscope package.
This is implemented by rendering the src
, srcset
and sizes
attributes as data-src
, data-srcset
and data-sizes
. The img- or pPicture-tag is then marked with the class lazyload
to
be replaced via js once the image comes into view. If you like you can render a very lowres
src-attribute or leave the src attribute empty (default).
- Martin Ficzel - ficzel@sitegeist.de
The development and the public-releases of this package is generously sponsored by our employer http://www.sitegeist.de.
Sitegeist.Lazybones is available via packagist run composer require sitegeist/lazybones
.
We use semantic-versioning so every breaking change will increase the major-version number.
To enable lazy loading you have to integrate a script that will detect the lazyload
class
and convert data-src
, data-srcset
and data-sizes
to the correct attributes once they come
into view.
This package includes the lazysizes
library from https://github.com/aFarkas/lazysizes
but it is probably better to include the js into your own fe-build.
To include the bundled js you can use the following snippet:
lazyloadJS = Neos.Fusion:Tag {
tagName = 'script'
attributes.async = true
attributes.src = Neos.Fusion:ResourceUri {
path = 'resource://Sitegeist.Lazybones/Public/JavaScript/lazysizes.min.js'
}
}
Render an img-tag with optional srcset based on sizes or resolutions.
This prototype is a drop in replacement for Sitegeist.Kaleidoscope:Image
with
optional props to control the lazy loading.
See: https://github.com/sitegeist/Sitegeist.Kaleidoscope#sitegeistkaleidoscopeimage
Props:
lazy
: Enable lazy loading (boolean, defaults toSitegeist.Lazybones:Lazy.Enabled
)lazyClass
: The class to attach to the img-tags (string, defaults toSitegeist.Lazybones:Lazy.ClassName
)lazyWidth
: The width of the thumbnail-src that is loaded first (string, defaults toSitegeist.Lazybones:Lazy.Width
)
Props from Sitegeist.Kaleidoscope:Image
:
imageSource
: the imageSource to rendersrcset
: media descriptors like '1.5x' or '600w' of the default image (string or array)sizes
: sizes attribute of the default image (string or array)format
: (optional) the image-format likewebp
orpng
, will be applied to theimageSource
width
: (optional) the base width, will be applied to theimageSource
height
: (optional) the base height, will be applied to theimageSource
alt
: alt-attribute for the img tagtitle
: title attribute for the img tagclass
: class attribute for the img tagrenderDimensionAttributes
: render width/height attributes if data is available from theimageSource
(boolean)
Render a picture-tag with various sources.
This prototype is a drop in replacement for Sitegeist.Kaleidoscope:Picture
with
optional props to control the lazy loading.
See: https://github.com/sitegeist/Sitegeist.Kaleidoscope#sitegeistkaleidoscopepicture
Props:
lazy
: Enable lazy loading (boolean, defaults toSitegeist.Lazybones:Lazy.Enabled
)lazyClass
: The class to attach to the img-tags (string, defaults toSitegeist.Lazybones:Lazy.ClassName
)lazyWidth
: The width of the thumbnail-src that is loaded first (string, defaults toSitegeist.Lazybones:Lazy.Width
)
Props from Sitegeist.Kaleidoscope:Picture
:
imageSource
: the imageSource to rendersources
: an array of source definitions that supports the following keysmedia
: the media query of this sourcetype
: the type of this sourceimageSource
: alternate image-source for art direction purposesrcset
: media descriptors like '1.5x' or '600w' (string or array)sizes
: sizes attribute (string or array)width
: (optional) the base width, will be applied to theimageSource
height
: (optional) the base height, will be applied to theimageSource
format
: (optional) the image-format for the source likewebp
orpng
, is applied toimageSource
andtype
srcset
: media descriptors like '1.5x' or '600w' of the default image (string or array)sizes
: sizes attribute of the default image (string or array)formats
: (optional) image formats that will be rendered as sources of separate type (string or array)width
: (optional) the base width, will be applied to theimageSource
height
: (optional) the base height, will be applied to theimageSource
alt
: alt-attribute for the picture tagtitle
: title attribute for the picture tagclass
: class attribute for the picture tagrenderDimensionAttributes
: render dimension attributes (width/height) for the img-tag when the data is available from the imageSource
Render a source-tag with optional srcset based on sizes or resolutions.
This prototype is a drop in replacement for Sitegeist.Kaleidoscope:Source
with
optional props to control the lazy loading.
Props:
lazy
: Enable lazy loading (boolean, defaults toSitegeist.Lazybones:Lazy.Enabled
)
Props from Sitegeist.Kaleidoscope:Source
:
imageSource
: the imageSource to rendersrcset
: media descriptors like '1.5x' or '600w' of the default image (string or array)sizes
: sizes attribute of the default image (string or array)media
: the media query of this sourcetype
: the type of this sourcewidth
: (optional) the base width, will be applied to theimageSource
height
: (optional) the base height, will be applied to theimageSource
format
: the image-format for the source likewebp
orpng
, is applied toimageSource
andtype
Boolean value prototype with default value true
that defines whether lazyness is enabled or not.
Override the value
of this prototype globally or for specific parts of your fusion.
String value prototype with default value lazyload
to define the class that marks lazyloaded images.
Override the value
of this prototype globally or for specific parts of your fusion.
Integer value prototype with default value null
to define the size of lowres images that are loaded as
placeholders. Override zhe value
of this prototype globally or for specific parts of your fusion.
To optimize the intial load time lazy loading should be disabled for the first contents but be enabled for others. This can be implemented by enabeling the lazy
in the ContentCase
prototype depending on wether or not the curent node
is the first content in the main collection.
content = Neos.Neos:ContentCollection {
nodePath = 'main'
content.iterationName = 'mainContentIterator'
// enable lazynes for all but first content
prototype(Sitegeist.Lazybones:Lazy.Enabled) {
value = ${!mainContentIterator.isFirst}
}
// preload 150px variants of the images
prototype(Sitegeist.Lazybones:Lazy.Width) {
value = 150
}
}
We will gladly accept contributions. Please send us pull requests.