Welcome! Log In Create A New Profile

Advanced

webp images

Posted by toft6633 
webp images
April 29, 2024 06:13AM
Hello,

I have just moved från Apache to Nginx.

I cannot set an expiration date for webp images. I use Drupal. I have uploaded png images to Drupal. Drupal converts them to webp and the files get the extension "png.webp".

This is my code in the service section.

location ~* \.(js|css|png|jpg|jpeg|gif|ico|webp|svg)$ {
try_files $uri /index.php?$query_string;
expires 1y;
}

It works for all files execpt webp. Lighthouse complains that I do not have an effiecnt cache policy for webp files. I can also see in the browser that they don't get an expiration date.

I have followed a lot of tutorials but none of them work for me. Here are som examples.

https://www.wpfastestcache.com/tutorial/how-to-serve-webp-images-on-nginx/
https://themify.me/docs/enable-webp-on-nginx-litespeed-servers

Help would be appreciated.

Fred
Re: webp images
May 01, 2024 05:53AM
I got it to work. When I in the same directory placed "example.png" and "example.png.webp", the latter was served. I also placed this code in Service section:

location ~* ^/.+\.(png|gif|jpe?g)$ {
expires 1y;
add_header Cache-Control "private,must-revalidate";
add_header Vary Accept;
try_files $uri$webp_suffix $uri =404;
}

In ../conf.d/webp.conf I placed this code:

map $http_accept $webp_suffix{
default "";
"~*webp" ".webp";
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 105
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready