1. Home
  2. Articles
  3. Web Hosting
  4. Dynamic Server Side webp Detection
Read about Server Side webp detection

Dynamic Server Side webp Detection




After playing around with the newest release of Google DevTools Lighthouse audits. I decided to take another look at a solution for dynamically delivery of webp image formats. There is still the problem that structured data image objects don't support the webp format, which kind of kills the whole idea of using webp format, but the savings on file size was worth another look.


Digging through several sites and partial answers to dynamically changing the image format of requested resources, I found the following answer worked for detection and delivery of webp images.

Adding the following to a .htaccess file should detect if the requesting browser accepts webp. Then it checks the server to see if a webp version of the requested image is available on the server. If both statements are true, the server delivers the webp image in place of the requested png, jpg or jpeg file.

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_ACCEPT} image/webp RewriteCond %{REQUEST_FILENAME} (.*).(jpe?g|png)$ RewriteCond %1.webp -f RewriteRule (.+).(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1] </IfModule>

The net savings on load times is excellent. Now if Google will just decide to support this format in the structured data model, we will be set!


Profile Picture of Bryan Myers - The Web Guy

Bryan Myers - "The Web Guy"

Advanced Digital Channel Engineer


  1. Articles discussing web related topics and technologies.Articles
  2. Articles covering Web Hosting.Web Hosting

Related Articles

Go Back