How to show webp image with falback url in image_tag rails

Viewed 1072

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

2 Answers

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>
Related