I want to show webp image urls with their fallback urls in image_tag rails.
Now its <%= image_tag "profile.webp",:class=>"profile" %>
How can I add fallback url of jpg url for browsers on which webp not working
I want to show webp image urls with their fallback urls in image_tag rails.
Now its <%= image_tag "profile.webp",:class=>"profile" %>
How can I add fallback url of jpg url for browsers on which webp not working
unfortunately, this isn't possible using the rails helper (image_tag).
You can take a look at https://github.com/kavu/sprockets-webp as a possible solution, however, this adds a lot of complexity.
Your best bet is solving this using JS: https://developers.google.com/speed/webp/faq
well, you can achieve it not by rails way, but by basic HTML-5 WAY, using picture tag
<picture>
<source srcset="/img.webp" type="image/webp" />
<source srcset="/img.jpg" type="image/jgpg" />
</picture>
Or in the below way too..
<picture>
<source srcset="/images/cereal-box.webp" />
<img src="/images/cereal-box.jpg" />
</picture>