Overriding rails_amp image helper to cater for lazy-loaded images
I make use of the rails_amp gem in the affiliate site. It generates AMP from normal views.
One of it’s features is automatically converting the image_tag
into the AMP compatible alternative.
The affiliate site however has lazy loading that uses jQuery lazy which means that instead of:
it mostly uses:
The rails_amp
gem then generates the AMP image tag for the placeholder image only.
To solve that the image tag helper rails_amp
can be overriden like this:
If data[src]
is present the source is overriden. Otherwise it functions the same as for regular image tags.