Image optimization: WebP, AVIF and lazy loading
· PoolByte Technology

Images often take up the largest share of the total size of a web page; That's why visual optimization is one of the most efficient starting points for speed work. If the large cover photo, product galleries and blog images on the home page are not prepared correctly, the page may remain on mobile connection for seconds. Moreover, the largest visible element of the page is usually an image, and how quickly that element appears directly impacts LCP from Core Web Vitals metrics.
Image optimization is not just about compressing the file. The right format, the appropriate resolution for the size it will be displayed in, the right upload priority and a few rules added to the publishing process will yield results.
Find the heaviest images first
Open the Network tab in the browser's developer tools, limit the filter to images, and sort the list by size. Compare which image is how many kilobytes and how many pixels wide it actually appears on the page. The recommendations in the Lighthouse report for sizing images correctly and presenting them in modern formats also provide a good starting list.
Usually a few files make up the bulk of the total weight. Initiating visual optimization starting from these files, rather than reworking the entire site, provides the fastest gain in terms of effort. To measure other components of page speed, you can refer to our Core Web Vitals guide.
Choose format based on content
There is no one right format for every image:
- For photos, WebP generally provides smaller files than JPEG and is supported by most current browsers.
- AVIF often offers even higher compression on photos; However, coding time is long and may not be supported on some older devices.
- For logos, icons, and simple illustrations, SVG remains clear at any resolution and is often very small.
- PNG can still be used for screenshots that require transparency; but WebP also supports transparency.
You can use <picture> to serve different formats together. The browser selects the first source it supports, if not, it returns to the standard image in the last line.
<picture>
<source srcset="kapak.avif" type="image/avif">
<source srcset="kapak.webp" type="image/webp">
<img src="kapak.jpg" alt="Ofiste toplantı yapan ekip" width="1200" height="675">
</picture>
Produce the image in the size it will be displayed
The most common mistake is to show a 4000 pixel photo taken with a phone in an 800 pixel area. The browser downloads the extra pixels but does not use them. Making the image approximately twice as wide as its widest view on the page is often sufficient for high-density displays.
Offer multiple sizes using srcset and sizes attributes for different screen widths. So the phone downloads the small file, and the widescreen downloads the large file. Be sure to include the attributes width and height; The browser allocates space before the image loads and the page content does not scroll.
Visually check compression quality
There is no linear relationship between quality setting and file size. For most photos, the medium-high quality setting will noticeably shrink the file, with an imperceptible loss. Export the same image at several different quality settings and compare side by side; In particular, skin tones, sky transitions and small text are the areas most susceptible to distortion.
Also clear EXIF information from photos. In addition to enlarging the file, this information may even include the location of the shooting location.
Use lazy loading on the right images
The loading="lazy" attribute ensures that images outside the visible area of the screen are not downloaded until the user approaches that area. It is very effective for long product lists and blog pages.
However, adding lazy loading to the cover image that appears immediately when the page is opened has the opposite effect and extends the LCP time. For this main image, you can inversely use fetchpriority="high" to tell the browser to request this file first. In short: the images on the first screen should load immediately, the following should load when necessary.
Add rules to the publishing process
If you do image optimization once and abandon it, the problem will return with newly uploaded images. Set simple rules with your team: maximum width, preferred format, file naming, and alt text requirement. Systems such as WordPress automatically generate different sizes of the uploaded image; Make sure these dimensions are compatible with the fields in your theme.
It is even more important to set a separate standard for product photos on e-commerce sites. Our e-commerce product page guide explains the shooting and preparation side. Serving images through a CDN and giving accurate cache times also makes a difference in repeat visits.
Frequently asked questions
Should I delete old JPEG files when I switch to WebP?
It is a good practice to keep the original files in backup. When you need to produce a different size or format in the future, you can start over from the quality source.
Is it harmful to add lazy loading to all images?
Yes, when added to the visuals that appear on the first screen. Delayed loading of these images delays the visual completion of the page. Use lazy loading only on images that appear when you scroll.