How to optimize images for site speed
Optimizing images means resizing and compressing them, serving WebP or AVIF and loading the ones below the first screen only when they are needed. Images are usually the heaviest part of a page, so unoptimized photos are the most common reason a site feels slow, and this work cuts page weight the most for the least effort. Start here if a speed test shows a large total page size made up mostly of images.
Check your site
-
Resize photos to the real container
Do not upload a 3000-4000 px photo if it is displayed in an 800 px block on the page. Before uploading, reduce its width in any image editor to the size it is displayed at, or about twice that for Retina screens.
-
Compress your images
Use JPEG for photos at quality 75-85 and keep PNG for graphics with transparency. Compress with a plugin such as ShortPixel or Imagify, or by hand in a tool like Squoosh before uploading. The file becomes several times smaller with no visible difference.
-
Switch to WebP or AVIF
WebP and AVIF files are 25-50% smaller than a JPEG of the same quality. In WordPress an optimization plugin creates them. On LiteSpeed hosting, LiteSpeed Cache can serve WebP automatically in place of JPEG to browsers that support it.
-
Set width, height and srcset
Add width and height attributes to the img tag so the browser reserves the space and the page does not jump while it loads. The srcset attribute serves a smaller image on mobile; WordPress adds it automatically when the media library holds several sizes of the image.
-
Enable lazy loading
Images below the first screen should load only when the visitor scrolls to them, so the browser does not spend time on photos nobody can see yet. Modern WordPress adds loading="lazy" by itself; check that your theme or a plugin has not turned it off.
-
Clear the cache and check several pages
After optimizing, purge the site cache (LiteSpeed Cache) and the CDN cache, then reload the page with Ctrl+F5. Check the home page, an article and a product page, since heavy old images most often linger on those.
How to verify the result
Run your home page and a couple of inner pages through the SpoofLens speed test before and after the changes: page size and load time should drop noticeably. Compare page weight in kilobytes, because that is where images give the biggest gain.
Tip: Do not lazy-load the main image on the first screen, such as a hero banner or the logo. Deferring the LCP image delays the moment the page appears and hurts your Core Web Vitals.