It appears that lazy_page_build() queries all input formats and all field configurations on every page build to determine whether or not to attach the lazy-loader JavaScript to the page.
There are a few issues with this:
- This seems like a heavyweight check relative to the minimal benefit of avoiding loading the library on some pages. On the frontend, does an error occur or a performance issue arise if the library loads and there are no images it needs to process on the page? If not, why not attach the library always, similar to how Image Lazy Loader functions.
- This limits what contexts image lazy loading can be used. In our site, for example, we have a Display Suite custom field that normally uses Core's
image_formattertheme function to render cover art for an item. It looks like the image formatter for Lazy is a drop-in replacement for the theme function, so it should be as easy as swapping'#theme' => 'lazy_image_formatter'in for'#theme' => 'image_formatter'in our render array. Unfortunately, because Lazy doesn't attach the JS to the page unless it finds either an input filter or a field configuration that uses the library, this doesn't work without extra code in our module that duplicates what Lazy does to ensure the library gets attached. - It only checks image fields. What about File API field types (like generic files) that support images among other types of files? Because the module is hard-coded to only look at image
As an aside, I don't understand why the status of whether or not the library is installed is passed via the lazy_library_installed configuration setting. This feels like a code smell; why doesn't lazy_is_library_installed() just detect the library and then maintain the status of whether or not the library was detected as a statically-cached local variable, so that you don't have to abuse and maintain a configuration setting for a transient library status that can change between page loads?
Comments
Comment #3
osmanI absolutely agree, those checks are unnecessary.
Now the JS is attached on all conditions, unless native lazy-loading is enabled. #3165001: Native image lazy-loading for the web