A developer can spend a week shaving milliseconds off JavaScript and lose to a single 4-megabyte hero photo that never got resized. Images are usually the heaviest thing on a page by an order of magnitude, and most sites still serve them at full camera resolution to a phone screen. Taliferro treats image optimization as a first-class performance lever, not an afterthought — because the fastest code in the world can't outrun an unoptimized JPEG.
Co-Founder Taliferro
Images enhance a page. They also tend to be the single largest thing on it, often by ten times or more compared to every line of HTML, CSS, and JavaScript combined. A camera-resolution photo dropped straight into a page and displayed at a fraction of its actual size is pure waste — bytes downloaded and decoded for detail nobody can see.
Choosing the appropriate image format is the first step in optimization. The most common formats for web images are JPEG, PNG, and GIF. Here's when to use each:
Many images used on websites are larger than necessary. Resizing images to match their display size can significantly reduce file size. Consider the maximum size at which an image will be displayed and resize accordingly.
Here's a code sample in HTML to set the image's display size:
<img src="your-image.jpg" alt="Description" width="300" height="200">
This code sets the image to be displayed at 300 pixels wide and 200 pixels high. Be sure to use actual dimensions that match your design.
Image compression is a critical aspect of optimization. It reduces file size without compromising image quality significantly. There are various tools and libraries available for image compression.
One popular tool for compressing JPEG images is TinyPNG. It allows you to upload images and download the compressed versions.
For PNG images, you can use TinyPNG as well, or consider using tools like ImageOptim or OptiPNG.
Here's an example of compressing a JPEG image using TinyPNG:
<img src="your-image.jpg" alt="Description">
In this case, you upload your image to TinyPNG, download the compressed version, and replace "your-image.jpg" with the optimized image.
If you want to automate image compression as part of your website's build process, consider using image compression libraries. For example, if you're using JavaScript, you can use libraries like ImageMin or Sharp to optimize images during development or deployment.
Here's an example of using ImageMin with Node.js:
const imagemin = require('imagemin');
const imageminPngquant = require('imagemin-pngquant');
const imageminJpegoptim = require('imagemin-jpegoptim');
(async () => {
const files = await imagemin(['images/*.{jpg,png}'], {
destination: 'build/images',
plugins: [
imageminJpegoptim(),
imageminPngquant({ quality: [0.6, 0.8] })
]
});
console.log('Images optimized:', files.map(file => file.path));
})();
This code snippet demonstrates how to use ImageMin with plugins like imageminJpegoptim and imageminPngquant to optimize JPEG and PNG images in a specified directory.
Lazy loading is a technique that defers the loading of offscreen images until the user scrolls down the page. This reduces the initial page load time.
Here's an example of lazy loading in HTML:
<img src="placeholder.jpg" data-src="your-image.jpg" alt="Description" loading="lazy">
In this code, the actual image URL is specified in the data-src attribute. The browser will load the image only when it comes into the user's viewport.
WebP is a modern image format developed by Google that offers excellent compression while maintaining image quality. It is particularly well-suited for the web due to its smaller file sizes compared to JPEG and PNG formats.
To use WebP images, you need to provide both WebP and fallback formats (JPEG or PNG) to ensure compatibility with all browsers. Here's how you can include WebP images in your HTML:
<picture>
<source srcset="your-image.webp" type="image/webp">
<source srcset="your-image.jpg" type="image/jpeg">
<img src="your-image.jpg" alt="Description">
</picture>
In the code above, the <picture> element includes a <source> element with the srcset attribute pointing to the WebP image. It also includes a <source> element for the fallback JPEG image. Browsers that support WebP will load the WebP image, while others will fall back to the JPEG.
To create WebP images from your existing JPEG or PNG images, you can use various tools and libraries. Google provides a command-line tool called cwebp for converting images to WebP format. Additionally, you can use online converters like Squoosh or integrate WebP conversion into your development workflow using image processing libraries.
Here's an example of using the cwebp command-line tool to convert an image:
cwebp -q 80 your-image.jpg -o your-image.webp
In this command, -q specifies the quality level (in this case, 80), and -o indicates the output file name.
By considering WebP as part of your image optimization strategy, you can further enhance your website's performance and deliver high-quality visuals to your users. This format is supported by most modern browsers, making it a valuable addition to your optimization efforts.
None of this is exotic. Right format, right size, real compression, lazy loading, and WebP where it's supported — that's the whole list, and it's usually worth more to page speed than any other single change a team can make. Taliferro builds this into every website development project by default, because shipping a beautiful hero image at ten times the size anyone will ever see isn't a design choice. It's a bug.
Tyrone ShowersIf you want execution instead of more rework, start with frontend delivery support, connect it to the Momentum System, or book a frontend consult.
Want this fixed on your site?
Tell us your URL and what feels slow. We’ll point to the first thing to fix.
Explore Taliferro's free tools: Ask TODD · Find · Email Signature Builder · SayIt · Lead Vault · Meet Maya — or become an affiliate.
More from the blog