<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jan Hohner</title>
    <description>The latest articles on DEV Community by Jan Hohner (@janhohner).</description>
    <link>https://dev.to/janhohner</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F87140%2Fe7ea1fb8-ed87-4a3d-860b-00890cb006b0.jpg</url>
      <title>DEV Community: Jan Hohner</title>
      <link>https://dev.to/janhohner</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/janhohner"/>
    <language>en</language>
    <item>
      <title>WebP support detection with @supports and @media</title>
      <dc:creator>Jan Hohner</dc:creator>
      <pubDate>Sun, 19 Apr 2020 10:31:50 +0000</pubDate>
      <link>https://dev.to/janhohner/webp-support-detection-with-supports-and-media-1fm</link>
      <guid>https://dev.to/janhohner/webp-support-detection-with-supports-and-media-1fm</guid>
      <description>&lt;p&gt;While developing Royal Ur (&lt;a href="https://royal-ur.com"&gt;https://royal-ur.com&lt;/a&gt;) I remembered the Audit feature in the Chrome Dev Tools. I fixed a couple of things and then came across the following hint: "Serve images in next-gen formats".&lt;/p&gt;

&lt;p&gt;I decided that it was time to properly learn about WebP, a file format developed by Google in 2010, which is now supported by Chrome/Chromium, Edge and Firefox. As I wanted to support all the browsers not supporting WebP, my first idea was to use the CSS &lt;code&gt;@supports&lt;/code&gt; feature. Turns out there unfortunately is no &lt;code&gt;@supports(webp)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript feature detection was not an option either. I did not want to rely on JavaScript for this and JavaScript still blocks rendering in browsers.&lt;/p&gt;

&lt;p&gt;After more searching I came across &lt;a href="https://engineering.naukri.com/2015/11/optimizing-css-background-images-using-webp/"&gt;https://engineering.naukri.com/2015/11/optimizing-css-background-images-using-webp/&lt;/a&gt;. They suggest using a combination of &lt;code&gt;@media&lt;/code&gt; and &lt;code&gt;@supports&lt;/code&gt; to detect features that were added to browsers at the same time or after support for WebP was added. Their approach unfortunately has two drawbacks: a) Firefox does not get WebP but does support it b) Safari gets WebP but does not support it.&lt;/p&gt;

&lt;p&gt;So with all this information and the great list of browser hacks at &lt;a href="http://browserhacks.com/"&gt;http://browserhacks.com/&lt;/a&gt; I set out to write WebP detection in CSS. This is the result:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;I hope this is useful for somebody. Let me know what you think!&lt;/p&gt;

</description>
      <category>css</category>
      <category>webperf</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
