ShortPixel webp is not written to disk with LiteSpeed plugin active
-
The generation of webp using ShortPixel stopped working some time after 14th of April. It works when LiteSpeed plugin is inactive. I’ve changed no settings and delivery of webp works as before for the images that does have them.
ShortPixel support team says: “I’ve seen this with another customer, but we can’t reproduce it in our environment, so it might be connected to some of the hosting environment settings”.
-
Without guaranteeing that I might be right, but it looks like Shortpixel creates the webp images on-the-fly. This requires PHP. When a page is cached, there is no more PHP. The output in the browser then only comes from a static file on the server. This is how any HTTP cache works. In your case, this means that you cannot use Shortpixel if Shortpixel does not create the webp images in advance using a separate service.
But as already mentioned, this is only an assumption, but a very probable one.
@serpentdriver Thanks for the suggestion. But ShortPixel creates and writes the webp to disk in the same directory as the other media files. Only this stopped working a month ago.
It can look like this:
my-image-100×150.jpg
my-image-100×150.jpg.webp
my-image-1024×1536.jpg
my-image-1024×1536.jpg.webp
my-image-300×450.jpg
my-image-300×450.jpg.webp
my-image-600×900.jpg
my-image-600×900.jpg.webp
my-image-768×1152.jpg
my-image-768×1152.jpg.webp
my-image-800×1200.jpg
my-image-800×1200.jpg.webp
my-image.jpg
my-image.jpg.webpThe location doesn’t matter, but LiteSpeed cache plugin also writes all converted images in the same directory where all other images are located. The difference is that cache plugin changes the file extension of each image and modifies the source of
<img>
tag. This method is quite different to almost any other plugin that creates webp images.Shortpixel also generates .webp images, but leaves the source of the
<img>
tag unchanged and uses a server function to provide webp. This means that the source remains the same, but the MIME-type is changed. This makes it look like the original image is being loaded, but it is actually the webp variant. If you see .webp images in the /upload directories, then the images with *.jpg.webp images are generated by LiteSpeed and not by Shortpixel, at least that’s what the Shortpixel documentation says.The advantage of this method is that not only is this method different, but it is not tainted with the bugs of other plugins. Shortpixel uses the Accept header to determine if a browser supports webp images. However, this method is very faulty and does not work fully with the Apple Safari browser. This means that certain Safari versions (have to) load webp images, even though these versions do not support webp at all.
Ultimately, this has nothing or almost nothing to do with your problem. It’s just that PHP is required for image conversion when it happens on-the-fly when a page is requested, but when a page is cached there is no more PHP. This fact has never changed.
@serpentdriver I hear what you are saying. But I’m using ShortPixel to create the webp images and LiteSpeed to serve them.
It is in fact ShortPixel that creates them.
I’m using this in wp-config which makes ShortPixel create them with double file extensions for LiteSpeed:define('SHORTPIXEL_USE_DOUBLE_WEBP_EXTENSION', true);
I have webp generation turned off in LiteSpeed.
The webp images are created before hand, not on the fly. My example file listing above was the result of:ls my-image*
And as I said this worked before and has worked for years. Something changed in LiteSpeed or ShortPixel to break this. And it’s not only on my site.
As I said before, I’m not claiming to be absolutely right. Especially since I only know the Shortpixel plugin in part. Unfortunately, I cannot get the same information from the Shortpixel documentation as you describe. Especially when it comes to the double file extension. If you’re actually right and unreservedly so, then there’s really no reason why Shortpixel shouldn’t work. However, there is something to check. Please look in the .htaccess in the root directory to see if you can find entries for webp replacement between the LiteSpeed markers.
Please look in the .htaccess in the root directory to see if you can find entries for webp replacement between the LiteSpeed markers.
What do you mean by that?
Assuming you are right when it comes to the generation, I don’t understand why this would stop working all of a sudden? How can you explain that?
What do you mean by that?
If you have access to the .htaccess, please do what I asked you to do.
Assuming you are right when it comes to the generation, I don’t understand why this would stop working all of a sudden? How can you explain that?
The need for PHP for image conversion has never changed. It’s the same as needing air to breathe. It would be helpful if you would post a link to your site. Then it would be easier to identify the problem.
@serpentdriver Thanks, this is what the webp part looks like in the .htaccess file:
### marker WEBP start ### RewriteCond %{HTTP_ACCEPT} "image/webp" RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp] RewriteCond %{HTTP_USER_AGENT} iPhone.*Version/(\d{2}).*Safari RewriteCond %1 >13 RewriteRule .* - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp] ### marker WEBP end ###
Example of working url with webp:
https://lotuseco.se/shop/klanning-dam-oversize-crepe-naturvit/
Example of non working url where webp has not been generated:
https://lotuseco.se/shop/klanning-oversize-fickor-finrandig-bla/Images in webp format don’t exist on your server:
@serpentdriver Exactly! That is the problem.
When I upload them to the media library ShortPixel should create them (once). But it does not happen when LiteSpeed cache plugin is active. This has worked until 1 month ago. Why has it stopped? Did something change in LiteSpeed or ShortPixel?
I think you understand my problem now?Then it’s probably like I said, that Shortpixel sometimes creates the images on-the-fly. But it’s not the fault of the cache plugin if the image conversion doesn’t work. Rather, it means that Shortpixel is not cache friendly.
So the problem can only occur when a page is cached and you add or change images.
Why has it stopped? Did something change in LiteSpeed or ShortPixel?
No, I think it was pure coincidence because the methodology hasn’t changed.
@serpentdriver I’m trying to get ShortPixel to answer here. I hope they will. I can’t really understand why the webp generation with ShortPixel worked for years with pure coincidence and now stopped working all the time. And ShortPixel can’t reproduce the issue it with LiteSpeed they say.
Would a plugin like EWWW work with LiteSpeed?
Which I only see now when I looked at the source code of your site. Shortpixel changes the source of the
<img>
tag. This is disastrous if Shortpixel does not also define the appropriate cache vary for it. This means: If you call up an uncached page with a browser that supports webp, then the page called up will be cached. If you call up the same page with a browser that does not support webp, then this browser gets webp images loaded, although it does not support this format at all. This means that this user will not see any pictures.Would a plugin like EWWW work with LiteSpeed?
The problem is repeated with every other plugin because none (except mine) is compatible with LiteSpeed cache plugin. The only exception are plugins, which leave the source code unchanged and do not create the images on-the-fly.
Hello @serpentdriver ,
This is Pedro from ShortPixel, trying to explain this with a bit more technical details. Our plugin – ShortPixel Image Optimizer – creates the WebP versions of the file after they are uploaded, with a JS processor that is triggered from wp-admin, therefore the generation itself should have nothing to do with the front-end cache because it happens through the wp-admin. I want to clarify that this is never done on the fly, therefore it has nothing to do with PHP working or not on cached pages. This process has worked very well, as @ben72 was saying, until some weeks ago when something strange started to happen: our plugin does the optimization, generates the WebP files, and sends the filesystem commands to write them to the disk, but for some reason, they don’t get written when LiteSpeed Cache is enabled. It looks as if the filesystem doesn’t exist, or simply doesn’t respond for WebP files, while the optimized JPG/PNG files are written correctly. We haven’t been able to identify anything in the logs about this and we also haven’t been able to reproduce this in our test environments using NGINX or Apache (we don’t have an environment with the LS webserver, unfortunately).
I also want to underline that the WebP serving on Ben’s site is done through the LiteSpeed Cache plugin, therefore ShortPixel isn’t touching the src of the images, that’s probably what LS Cache is doing.
Do you, or somebody from the LS Cache development team could have any ideas about what could cause this strange behavior with writing files when the LS Cache plugin is enabled?
Thanks!
- The topic ‘ShortPixel webp is not written to disk with LiteSpeed plugin active’ is closed to new replies.