Skip to content
Speed and performance5 min read

How to optimize images for a faster website

Short answer

Resize each image to the largest size it's actually shown at, compress it, and serve it as WebP or AVIF, with JPEG or PNG as a fallback where needed. Add width and height attributes, use srcset so phones download smaller files, lazy-load images below the fold, and never lazy-load the main image at the top of the page.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Before you start
  2. Step by step
  3. Troubleshooting
  4. On ArabyHost

On most pages, images make up the largest share of the bytes downloaded. A photo straight from a phone camera can be several megabytes and thousands of pixels wide, while the slot it fills on a phone screen is a few hundred pixels. Optimizing images means sending each visitor only the pixels they’ll actually see, in the most efficient format their browser supports.

Before you start

  • Tools: an image editor, or command-line tools on your computer: cwebp (from Google’s WebP package), avifenc (from libavif) and ImageMagick. For a single image, a browser-based tool such as Squoosh works fine.
  • Display sizes: in Chrome, right-click an image » Inspect and hover over the <img> tag. DevTools shows the rendered size and the intrinsic (file) size. A big gap between them means wasted bytes.
  • For WordPress: admin access and a backup of wp-content/uploads before bulk changes.

Step by step

1. Find the heavy images

Run PageSpeed Insights and open Improve image delivery, which lists each image with the possible saving. Or in DevTools » Network, filter by Img and sort by Size.

2. Choose the right format

Content Recommended format Notes
Photos AVIF or WebP JPEG as fallback for old software
Logos, icons, simple illustrations SVG Sharp at any size, usually tiny
Screenshots, images with transparency WebP (lossless) or PNG Lossy JPEG blurs text edges
Animations MP4 or WebM video An animated GIF is many times larger

3. Resize to the displayed size

Typical targets: full-width hero images about 1600 to 2000 pixels wide, images inside content 800 to 1200 pixels, thumbnails 300 to 400 pixels. Uploading a 4000-pixel photo for an 800-pixel slot wastes most of the download. With ImageMagick:

magick photo.jpg -resize 1600x -strip -quality 82 photo-1600.jpg

-resize 1600x sets the width and keeps the proportions; -strip removes camera metadata, including GPS location. On ImageMagick 6, use convert instead of magick.

4. Compress and convert

cwebp -q 80 photo-1600.jpg -o photo-1600.webp
avifenc -q 60 photo-1600.jpg photo-1600.avif

# convert a whole folder to WebP
for f in *.jpg; do cwebp -q 80 "$f" -o "${f%.jpg}.webp"; done

AVIF’s quality scale behaves differently from JPEG’s, so a lower number often gives a similar look. Compare the results side by side before replacing the originals.

5. Serve responsive images

Let the browser choose the right file for the screen and format support:

<picture>
  <source type="image/avif"
          srcset="photo-800.avif 800w, photo-1600.avif 1600w"
          sizes="(max-width: 800px) 100vw, 800px">
  <source type="image/webp"
          srcset="photo-800.webp 800w, photo-1600.webp 1600w"
          sizes="(max-width: 800px) 100vw, 800px">
  <img src="photo-800.jpg"
       srcset="photo-800.jpg 800w, photo-1600.jpg 1600w"
       sizes="(max-width: 800px) 100vw, 800px"
       width="800" height="533" alt="Description of the photo"
       loading="lazy" decoding="async">
</picture>

sizes tells the browser how wide the image will be on screen, so a phone picks the 800-pixel file while a sharp laptop screen may pick the 1600-pixel one.

6. Lazy-load below the fold, prioritize the hero

Add loading="lazy" to images further down the page so they load only as the visitor scrolls. Do the opposite for the main image at the top: no lazy loading, and fetchpriority="high". Always include width and height; without them the page jumps as images arrive, which hurts layout shift in Core Web Vitals.

7. In WordPress

  • WordPress creates several sizes of every upload and adds srcset automatically. Adjust the sizes under Settings » Media.
  • Images larger than 2560 pixels are scaled down automatically on upload, and WebP uploads are supported, as is AVIF when the server’s image library supports it.
  • In LiteSpeed Cache » Image Optimization, send your library for optimization through the QUIC.cloud service. It compresses images and creates WebP or AVIF copies; then enable the next-generation format replacement in Image Optimization Settings so supporting browsers receive the new files. Lazy loading is under Page Optimization » Media Settings.
  • Use only one image optimization plugin; two will process the same files twice or conflict.

8. Use a CDN for images

A CDN serves images from locations close to each visitor, which matters most when your audience is far from the server.

Troubleshooting

  • Images still arrive as JPEG: purge LiteSpeed Cache and the CDN, then check the response header in DevTools; content-type: image/webp confirms the new format.
  • Images look blurry on phones: the file is too small for high-density screens. Add a version about twice the displayed width to srcset.
  • WordPress upload fails with “HTTP error”: see image upload HTTP error.
  • The page jumps while loading: an image is missing width and height.
  • WordPress refuses AVIF uploads: the server’s image library lacks AVIF support for that PHP version; upload WebP instead.

For the rest of the page, see the complete website speed guide.

On ArabyHost

Sites run on LiteSpeed, and LiteSpeed Cache, with its Image Optimization and lazy-load options, comes with one-click WordPress and WooCommerce installs. Every image size WordPress generates is a separate file, so optimized, well-sized images also save disk space and inodes, and keep your daily JetBackup backups smaller. Files are served from the data center in Germany; if many of your visitors are in the Gulf or North Africa, a CDN in front of your images shortens the distance. File Manager in cPanel, opened with one click from the Araby Panel, handles uploads for non-WordPress sites.

FAQ

Should I use WebP or AVIF?

AVIF is usually smaller at the same visual quality but slower to encode; WebP is quicker to produce. Current major browsers support both, so either is a good choice, and many sites serve AVIF with WebP or JPEG as a fallback.

What compression quality should I use?

For photos, a quality of around 75 to 85 in JPEG or WebP usually looks the same as the original at a fraction of the size. Compare at 100% zoom, lower the quality until you notice artifacts, then go back up a step.

Does compressing images hurt SEO?

No, it helps, as long as you keep descriptive file names and alt text. Lighter images improve Largest Contentful Paint, and Google Images indexes WebP and AVIF files.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.