Skip to content

Add a nginx config to automatic avif/webp instead of jpg #2000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yodatak opened this issue May 2, 2025 · 1 comment
Open

Add a nginx config to automatic avif/webp instead of jpg #2000

yodatak opened this issue May 2, 2025 · 1 comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads)

Comments

@yodatak
Copy link

yodatak commented May 2, 2025

Feature Description

Thanks for making wordpress bether

i would love to use lot Modern Image Formats and by default to generate webp and avif file on upload ( and maybe on bulk conversion but annother issue)

i think we could use a nginx config like this

exemple on upload i have
Manif_XXL.jpg
and it become
Manif_XXL-jpg.avif

but i think its harder because of this format so it could be awsome to provide some nginx conf that do the avif/webp rewite

exemple from compresx extention

# BEGIN CompressX
set $ext_avif ".avif";
if ($http_accept !~* "image/avif") {
  set $ext_avif "";
}

set $ext_webp ".webp";
if ($http_accept !~* "image/webp") {
  set $ext_webp "";
}

location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
  add_header Vary Accept;
  add_header Cache-Control "private";
  expires 365d;
  try_files
    /wp-content/compressx-nextgen/$path.$ext$ext_avif
    /wp-content/compressx-nextgen/$path.$ext$ext_webp
    /wp-content/$path.$ext
  $uri = 404;
}
# END CompressX

maybe we could do something like this

set $ext_avif ".avif";
if ($http_accept !~* "image/avif") {
  set $ext_avif "";
}

set $ext_webp ".webp";
if ($http_accept !~* "image/webp") {
  set $ext_webp "";
}
  location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
    add_header Vary Accept;
    try_files $uri$avif_suffix$webp_suffix $uri$avif_suffix $uri$webp_suffix $uri =404;
  }
}

there is multiples plugins that use some close fonctionnality

some documentation
https://github.com/ksanksana/Otus/blob/main/10_Optimization/conf_optimized/wordpress
https://vincent.bernat.ch/en/blog/2021-webp-avif-nginx
https://www.lazutkin.com/blog/2014/02/23/serve-files-with-nginx-conditionally/
https://compressx.io/docs/config-nginx-htaccess-rules/

@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 May 2, 2025
@westonruter westonruter added the [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) label May 5, 2025
@westonruter
Copy link
Member

Hello! I'm not sure I understand. The plugin does already generate WebP or AVIF upon upload, and then it rewrites the image URLs to point to the modern image format when the page is rendered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads)
Projects
Status: Not Started/Backlog 📆
Development

No branches or pull requests

2 participants