Remix.run Logo
breve 5 days ago

> Devs often argue that the format is "sharper".

You can also use lossless WebP in place of PNG these days.

Theodores 5 days ago | parent [-]

You can get your code to list PNG or JPG and then get your server to serve webp. Browsers don't care about file extensions, they read the image headers.

To implement this you can get nginx to generate the webp from the JPG or PNG. Then you get that cached by your CDN.

If you need to change your compression levels then you can delete the cache on the CDN.

You can use the varies header to see if webp is accepted. If not, serve the original. In this way people can save the hires JPG with a right click.

You can also amp up the compression just for when the data saving flag is set.

The best thing is that you can do all this with hardly any lines of code and the VIPS library to optimise it.