Closed redlet closed 4 years ago
I was just looking for a solution to this issue so it's coincidental you posted this. From the source, it appears your images need to be in the uploads folder with the extension .jpeg.webp
, .jpg.webp
, or .png.webp
. I made this change since I was storing as only .webp
, but the problem persists even after re-converting all images and clearing the cache.
I'm using Nginx 1.7.10 and PHP 7.4.5 along with WebP Express.
@bridgettewp WebP Express says to use "Set .webp" not "Append .webp." Either way, it's broken in both cases.
That's correct -- I may have been wrong. I was reading the Cache Enabler code.
Importantly, I have determined the issue occurs when the page is viewed first in a WebP-capable browser. If I clear all WebP images and the cache then visit from a WebP-incapable browser first, the cache stores correct HTML files.
@svenba Have you experienced this behavior before?
This sounds like a conflict with another plugin. Try to disable any WebP related plugins, purge the CE cache and try again.
@svenba In my test setup, the only two active plugins are WebP Express (varied image mode) and Cache Enabler. I'm wondering if Nginx may be playing a role here in creating this issue. I have Brotli compression enabled (gzip disabled in Cache Enabler). Everything else is fairly standard.
I have these rules in my Nginx config and the WebP Express tests pass:
location ~* ^/?(?<noext>wp-content/.*)\.(png|jpe?g)$ {
add_header Vary Accept;
add_header Cache-Control "public, max-age=31536000, stale-while-revalidate=604800, stale-if-error=604800";
if ($http_accept !~* "webp") {
break;
}
try_files /wp-content/webp-express/webp-images/doc-root/$noext.webp
$noext.webp
/wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content
;
}
location ~* ^/?wp-content/.*\.webp$ {
add_header Cache-Control "public, max-age=31536000, stale-while-revalidate=604800, stale-if-error=604800";
try_files $uri
/wp-content/plugins/webp-express/wod/webp-realizer.php?xdestination=x$request_filename&wp-content=wp-content
;
}
Disable WebP Express, purge the CE cache and try again.
I just did that and confirmed the cache generated new files. I am still seeing ".webp" in both files.
Edit: For additional information, I am testing using Firefox (WebP), Chrome (WebP), and Safari (non-WebP). I do not think this affects caching outcomes, but in an effort to resolve this issue, anything could be useful to know.
@bridgettewp If I view the page on Firefox without the image/webp
header, the cache is correct, but if I enable the header, the cache is generated incorrectly. This sounds like what you mentioned. I can't currently test without additional plugins because I do not have a test setup, but none of them conflict with webp, caching, or optimization.
If there is no issue with CE on the latest version of PHP running via an Nginx web server, my only thought is the "Alter HTML" section of WebP Express causing issues, but I have it configured exactly as it should be.
That's it: "Alter HTML" section of WebP Express causing issues
@svenba https://i.ibb.co/8mLwkyQ/image.png These are my settings. The reason I use Cache Enabler is because of its support for two cached items per page (one for WebP and one not). Is it not possible to achieve?
Final comment: I see Cache Enabler alters the HTML for me. Everything seems to be working properly. Thank you for working through this @redlet and @svenba.
$ cat wp-content/cache/cache-enabler/x.com/index.html | grep .png
$ cat wp-content/cache/cache-enabler/x.com/index-webp.html | grep .png
They're both the same. Doesn't always happen, but most of the time it does.