Class: Banzai::Filter::ImageLazyLoadFilter
- Inherits:
-
HTML::Pipeline::Filter
- Object
- HTML::Pipeline::Filter
- Banzai::Filter::ImageLazyLoadFilter
- Includes:
- Concerns::PipelineTimingCheck
- Defined in:
- lib/banzai/filter/image_lazy_load_filter.rb
Overview
HTML filter that moves the value of image ‘src` attributes to `data-src` so they can be lazy loaded. Also sets decoding to ’async’ so that the decoding of images doesn’t block the loading of other content.
Constant Summary collapse
- CSS =
'img'
- XPATH =
Gitlab::Utils::Nokogiri.css_to_xpath(CSS).freeze
Constants included from Concerns::PipelineTimingCheck
Concerns::PipelineTimingCheck::MAX_PIPELINE_SECONDS
Instance Method Summary collapse
Methods included from Concerns::PipelineTimingCheck
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/banzai/filter/image_lazy_load_filter.rb', line 15 def call doc.xpath(XPATH).each do |img| img['decoding'] = 'async' img.add_class('lazy') img['data-src'] = img['src'] img['src'] = LazyImageTagHelper.placeholder_image end doc end |