Website image optimization: several practical points on dimensions, alt text, and formats

Images are often a major factor slowing down web page loading. This article explains common image optimization practices from four aspects: dimensions and aspect ratio, alternative text, compression formats, and distribution and loading methods.

花里云 约 1 分钟阅读~1 min read

Slow page loads are often not a code problem, but an image problem. A single unprocessed high-resolution image can consume more resources than all the text on the page combined. Image optimization does not require complex tools; going through a few areas can produce noticeable improvement.

First, control dimensions and aspect ratio

The most common waste is uploading original images much larger than the area where they will be displayed. Browsers do not make an image clearer just because it is large—they will first spend time downloading it, then scale it down for display. A better approach is to first determine the actual width the image occupies on the page, then export it as needed. The aspect ratio should also be fixed in advance; a common practice is to crop to a uniform aspect ratio to avoid stretching and distortion on the front end.

Write good alt text

Alt text for images serves two purposes: telling users what an image is when it fails to load, and helping screen readers and other assistive tools describe the content. It is not a place to stuff keywords, but should accurately explain the image content. Decorative elements (solid-color dividers, background textures) can be left empty to avoid interfering with reading; images with actual information—product photos, diagrams, screenshots—deserve a clear description of what they show.

Choose compression by type

Compression does not mean always pushing quality to the lowest setting. Photo content is suitable for lossy compression, where the loss in quality is almost invisible to the eye while the file size can drop significantly; graphics that need sharp edges, such as icons and logos, are suitable for formats that preserve crisp edges and transparency. In recent years, new formats such as WebP and AVIF, widely supported by mainstream browsers, usually have smaller file sizes at the same quality and are worth making the default choice; for scenarios with high compatibility requirements, a traditional format can be kept as a fallback. In addition, metadata such as the capture device and location carried in images can be removed as well if it is not intentionally kept.

Distribution and loading methods

Even if images are already optimized locally, cross-region access may still be slow due to long network paths; in this case, a content delivery network can noticeably improve the experience—by caching images on nodes closer to visitors. Images below the fold can be lazy-loaded: request them when the user scrolls near them, reducing the wait when opening the page. Cache duration should be set according to how often images are updated; promotional images that change frequently should not be set too long, while assets that remain unchanged for a long time can be set longer.

Image optimization is work that pays off long term once done. Setting the rules in place and writing them into the content publishing process is easier than handling it ad hoc before every launch.

花里云

西安花里云网络信息科技有限公司 · 企业数字平台厂商。十年一线交付,把项目里验证过的判断,整理成可以复用的东西。Xi’an Holypro Network Information Technology Co., Ltd. · an enterprise digital platform vendor. A decade of delivery, turning proven judgments into reusable assets.