大网数据广告活动
网站运营与故障问答

Blank image. What to use: Base64 vs 1x1 JPEG image

· 52CE 我爱测

I am building a website and I want to make HTTP queries as few as possible for a better website speed and seo. The page I just created is showing images on scroll (images have an attribute data-scr which is converted to src when …

问题原文

原帖链接 · ITChristian · CC BY-SA 3.0

I am building a website and I want to make HTTP queries as few as possible for a better website speed and seo. The page I just created is showing images on scroll (images have an attribute data-scr which is converted to src when the user scrolls down at the respective image).

Because all images have the data-src attribute instead of src, W3C shows me errors.

At this moment I found two options, to solve this problem:

  1. The initial src of all images to be an url of a blank 1x1 image
  2. The initial src of all images to be a data base 64 blank image

When I am using an URL of a blank 1x1 image, then (tested with tools.pingdom.com) it shows 1 HTTP request. When I am using a data base64 blank image then it shows as many requests as the number of images on page.

Which of them is the more efficient way, for a website faster speed and makes fewer HTTP requests? (let's suppose that the user is loading the webpage at a 14.4kbps internet speed - first internet speed).

But for SEO?

Is there any other option?

已采纳解答

原帖链接 · Chris Rutherfurd · CC BY-SA 3.0

The base64 image option should be used where you would only have a very small number of images and you want to eliminate the network overhead of fetching a picture from the server. However from what you are indicating in the question I assume this could scale to a large number of images. In this case I would use a single 1px x 1px transparent image from the server with a long cache lifetime as it will be fetched from the server once then cached in the browser and any intermediate proxy servers.

As an example this image would be around 95 bytes in size (https://commons.wikimedia.org/wiki/File:1x1.png), for a base64 encoded image string you would find the size would be on par with this image file size but would be repeated for every single image you add it to.

For 2-5 images the size and speed would be negligible and would decrease server traffic by eliminating one whole fetch, but for more than that the page size would start to get too large which would affect loading times and in turn SEO ranking.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。