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"
orloading="auto"
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.
- 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.
- The affects of this plugin are applied to the cache entry when it is saved using the
- Activating/deactivating this plugin will clear the Front Cache.
Just turn on the plugin in your admin settings.
Add this line to your application's Gemfile:
gem 'camaleon_lazy_loader'
And then execute:
$ bundle
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
- 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.
The gem is available as open source under the terms of the MIT License.