No release in over 3 years
Low commit activity in last 3 years
Adds browser-native loading="lazy" attribute to images and iframes rendered by Camaleon CMS.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 5.2
 Project Readme

Gem Version Ruby Style Guide Build

CamaleonLazyLoader

This plugin adds a loading="lazy" attribute to <img> and <iframe> tags rendered by Camaleon CMS.

  • This attribute will be added to tags on all server-rendered pages.
  • Existing loading attributes will not be overwritten, so you can still set individual tags to loading="eager" or loading="auto"

How it works

This plugin updates the body of the http response using the front_after_load hook provided by Camaleon, unless the page is cached with the Front Cache plugin. Nokogiri is used to add the loading attribute.

If the Front Cache plugin is active

  • For pages that are not cached, this plugin works as described above.
  • For pages that are cached:
    • The affects of this plugin are applied to the cache entry when it is saved using the front_cache_writing_cache hook.
    • There is no processing when reading from the cache.
  • Activating/deactivating this plugin will clear the Front Cache.

Usage

Just turn on the plugin in your admin settings.

Installation

Add this line to your application's Gemfile:

gem 'camaleon_lazy_loader'

And then execute:

$ bundle

Limitations

This gem uses Nokogiri, which in turn wraps underlying parsers. Some characters can be altered by these parsers when used in element attributes. Known cases include:

  • The AMP lightning bolt ⚡
  • Characters that are escaped in HTML, such as endash or ampersand

Contributing

  • Fork the repo.
  • Make your changes and add tests as necessary. (Run tests with rails test)
  • Run standardrb to lint your code.
  • Submit a pull request.

License

The gem is available as open source under the terms of the MIT License.