by cubano · 7y ago · 0 comments
Currently, I'm converting all the jpegs to webp at 55 compression at the time of import and I love both the quality and the sizes of the files, and so far couldn't be happier with the results[0] I managed to shave some 20GB from the disk usage as well.
The 800lb gorilla is, however, Safari. We all know that Safari does not currently support webp and due to internal politics, may never do so.
So the first "solution" is to keep copies of both formats and use the <picture> tag. This just won't do I have zero interest in doubling my already prodigal disk usage.
There are some rather complicated OS libs that will take a jpg and convert on the fly to webp...I want to do it the other way around.
One thing I hate are "kitchen sink" libs that do SO much that you are often left confused on how to do the specific thing you want to do, so I am in the process of rolling my own solution by using GD and intelligently converting the 11% of all requests that are Safari and using nginx caching to keep these converted images ready to go.
I would like to hear of anyone with better solutions, if possable, since as you can see, I haven't yet implemented my ideas.
It would be really great if there was an on-the-fly conversion library -- basically, reference the image once and let the run-time deliver up the right image type. What I don't like about that is that I generally shy away from doing any sort of "if then" based on browsers' user-agent-string.Edit/Update: I don't like that that because it got us all into a lot of trouble during the Browser Wars[0] and is now generally considered bad practice. [1]
This might get me some downvotes... but hold my beer and watch this: I wonder if there is a javascript solution? Maybe you serve up the webp images, always, and write your own jquery plug-in that converts the webp to jpeg in memory and then writes it to an HTML5 canvas, but only if it's safari/IE?
[0] https://youtu.be/yRkQOw1uRrw?t=164
[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_de...
Can't you just base it on the "Accepts" header? That's the whole reason it exists, after all.
If you go that route, be aware that HTTP caching mechanics can get tricky, and some CDN service providers (deliberately and self-interestedly) violate the rfc's (eg refuse to cache anything w/ a "Vary" response header at all -- looking at you Akamai)...
In retrospect, it was great fun to effectively piece together a web performance optimization service layer to support and accelerate the heck out of a traditional 3-tier web application... but doing it all by hand, these days, might not have great ROI.
Other things like making thumbnails of all the images can also help reduce bandwidth but depends on how the site is structured.