We have nodes with a lot of inline images in them. And we are looking for a solution on how to lazyload inline images in Drupal 8.
We are trying to get the Blazy module to lazyload them but it is not working that smoothly since we have a ton of posts already and can't manually apply the src-data
attribute and class
to all existing images.
This is how I am trying to get blazy to lazyload all images, but it is not working. Any ideas on what we are doing wrong? We are open to all recommendations.
Apply lazyload / blazy to all images.
1) In mytheme.libraries.yml
I added the following:
dependencies:
- blazy/load
2) In MYTHEME.info.yml
I added the following
libraries:
- 'mytheme/global-styling'
- 'mytheme/local'
3) In MYTHEME.theme
I added the following:
/**
* Implements hook_page_attachments_alter()
*/
function MYTHEME_page_attachments_alter(array &$attachments) {
$attachments['#attached']['library'][] = 'blazy/load';
}
What is wrong?
Currently getting this error:
Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in /core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php on line 138