When building websites, we spend plenty of time choosing frameworks, optimizing JavaScript, and improving database queries.
But there's another decision that can affect website performance: the image format.
JPEG has been around for decades, and it still works well. However, newer formats such as WebP give developers more options when balancing file size and visual quality.
So should we convert every JPEG image to WebP?
Not necessarily.
Let's explore when it makes sense and when it doesn't.
Why JPEG is still everywhere
JPEG is one of the most widely supported image formats.
It works across browsers, operating systems, image editors, and countless older applications.
For photographs, JPEG remains a perfectly reasonable choice.
But JPEG compression has limitations.
At aggressive compression settings, images can develop noticeable artifacts, particularly around text, edges, and detailed areas.
Modern formats offer different compression techniques that may achieve better results.
What makes WebP different?
WebP is an image format developed by Google.
It supports lossy and lossless compression, along with transparency and animation.
One of its biggest advantages is that photographic images can often be stored in smaller files than equivalent-looking JPEGs.
For example, you might have a JPEG photograph that's several hundred kilobytes.
After converting it to WebP, the result may become noticeably smaller while still looking similar.
However, this isn't guaranteed.
The savings depend on the image content, original compression, and conversion settings.
An already optimized JPEG might not benefit much from conversion.
How does this affect actual website performance?
Suppose you're building an e-commerce product page.
The page contains twelve product photographs.
If each image is unnecessarily large, the total image payload can quickly become significant.
Reducing the weight of those assets means fewer bytes need to travel over the network.
That can help with loading performance, particularly on slower connections.
But file size isn't the only performance factor. Image dimensions, network conditions, decoding time, caching, and loading priority matter too.
WebP is useful, but it's not a substitute for a complete optimization strategy.
Serving WebP with a JPEG fallback
Modern browsers support WebP, but keeping a JPEG fallback can still make sense for legacy environments and certain workflows.
The HTML <picture> element allows you to provide alternative formats:
<picture>
<source
srcset="/images/product.webp"
type="image/webp"
>
<img
src="/images/product.jpg"
alt="Wireless keyboard on a desk"
width="800"
height="600"
>
</picture>
A browser that supports WebP can use the WebP source.
If WebP isn't supported, the JPEG image remains available.
This is particularly useful when compatibility with older browsing environments is a requirement.
For modern applications without those compatibility requirements, using WebP directly may be sufficient.
Converting existing JPEG assets
You don't always need to change your application's code to prepare WebP files.
For a Node.js build pipeline, the Sharp library is one option.
Here's a small example:
import sharp from "sharp";
await sharp("product.jpg")
.webp({ quality: 80 })
.toFile("product.webp");
console.log("Image converted.");
This reads an image, converts it to WebP with a specified quality setting, and writes the output file.
For a larger project, you could extend this to process an entire assets directory.
But sometimes you just want to convert five or ten images manually.
In those situations, I like the simplicity of a browser-based converter.
ImgTask's JPG to WebP Converter allows you to select JPEG images, adjust the output quality, and download the converted files.
It also supports multiple image uploads, and the conversion happens locally in the browser rather than uploading the files for server-side processing.
It's a convenient alternative when setting up a full image-processing pipeline would be unnecessary.
Be careful with repeated conversions
Here's something worth remembering.
JPEG uses lossy compression.
If you convert a JPEG to lossy WebP, you're compressing data that has already been compressed.
That means conversion cannot magically recover details lost in the original JPEG.
Repeated conversions can introduce additional degradation.
Whenever possible, generate your final image formats from a high-quality original.
For example:
Original high-quality image
|
|
----------------
| |
JPEG output WebP output
This is generally better than:
Original → JPEG → WebP → JPEG → WebP
The second workflow introduces unnecessary recompression.
When should you keep JPEG?
Despite WebP's advantages, JPEG still makes sense in several situations.
Some external platforms and older applications expect JPEG uploads.
Printing workflows may require specific image formats or color-management handling.
You might also be working with an existing image pipeline that already generates well-optimized JPEGs.
And sometimes the actual file-size difference is so small that conversion provides little practical benefit.
Choose a format based on your project's needs rather than simply choosing the newest option.
A practical workflow
For most modern websites, I'd suggest this approach:
- Keep a high-quality original image.
- Resize it to the dimensions your interface needs.
- Generate a WebP version.
- Compare quality and file size against JPEG.
- Test the image in its actual page layout.
- Keep a JPEG alternative where compatibility matters.
You don't have to convert everything at once.
Start with the largest images on your most important pages and measure the results.
Final thoughts
WebP isn't a magic solution for slow websites, but it is a useful tool.
When combined with sensible dimensions, responsive images, and good loading strategies, it can help make pages lighter.
The goal isn't to use the most modern image format everywhere.
The goal is to deliver images that look good without transferring unnecessary data.
That's a much better way to think about image optimization.
Are you using WebP, AVIF, or traditional JPEGs in your current projects?
Top comments (0)