减少1000张图片的HTTP请求?

发布于 2024-10-09 17:06:49 字数 286 浏览 7 评论 0原文

我知道这个问题可能听起来有点疯狂,但我坚信也许有人能想出一个聪明的主意:

想象一下,您在单个 HTML 页面上有 1000 个缩略图。

图像大小约为5-10 kb。

有没有办法在单个请求中加载所有图像?以某种方式将所有图像压缩到一个文件中......

或者您对此主题还有其他建议吗?

我已经知道的其他选项:

CSS sprites

延迟加载

设置过期标头

跨不同主机名下载图像

I know this question might sound a little bit crazy, but I tough that maybe someone could come up with a smart idea:

Imagine you have 1000 thumbnail images on a single HTML page.

The image size is about 5-10 kb.

Is there a way to load all images in a single request? Somehow zip all images into a single file…

Or do you have any other suggestions in the subject?

Other options I already know of:

CSS sprites

Lazy load

Set Expire headers

Downloads images across different hostnames

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

五里雾 2024-10-16 17:06:49

鉴于您的情况,我只能想到两个其他选项:

  1. 使用“data:”协议并将缩略图的 base64 编码版本直接回显到 HTML 页面中。我不建议这样做,因为您无法在用户浏览器上缓存这些图像。
  2. 使用 HTML5 的 Web 存储将所有图像存储为记录,并将 base64 编码的图像数据存储为列中的 BLOB。将数据库下载到用户计算机后,使用 Javascript 循环遍历所有记录,并使用 jQuery 等动态在页面上创建缩略图。使用此选项,您需要等到整个数据库在最终用户浏览器上下载完成,并且他们将需要一个相当现代的浏览器。

我认为最好的选择是延迟加载、使用过期标头进行缓存以及从多个主机名提供图像的组合。

如果图像可以按逻辑分组,那么除了上述所有内容之外,CSS 精灵也可能适合您。例如,如果您的缩略图是在某一天上传的图像...您可以为每天创建一个文件,然后将其缓存在用户浏览器上。

There are only two other options I can think of given your situation:

  1. Use the "data:" protocol and echo a base64 encoded version of your thumbnails directly into the HTML page. I would not recommend this since you cannot then cache those images on the users browser.
  2. Use HTML5's Web Storage to store all the images as records with the base64 encoded image data stored as BLOBs in a column. Once the database has downloaded to the users machine, use Javascript to loop through all the records and create the thumbnails on the page dynamically using something like jQuery. With this option you would need to wait till the entire database was done downloading on the end users browser, and they will need a fairly modern browser.

I think your best bet is a combination of lazy loading, caching with expires headers and serving images from multiple hostnames.

If the images can be grouped logically, CSS sprites may also work for you in addition to everything above. For example, if your thumbnails are for images uploaded on a certain day...you may be able to create a single file for each day which could then be cached on the users browser.

你是暖光i 2024-10-16 17:06:49

这是通过使用所谓的 CSS sprite 来完成的;包含所有其他图像的单个图像,以及 css 选择的 html 中所需的特定部分。

请参阅 http://css-tricks.com/css-sprites 上的教程

This is done by using what's called a CSS sprite; a single image with all the other images inside it, with the particular part that's wanted in the html selected by css.

See one tutorial at http://css-tricks.com/css-sprites

兮子 2024-10-16 17:06:49

It sounds like you want something like SPDY's server push. When the client requests the HTML page (or the first image), SPDY allows the server to push the other resources without waiting for more requests.

Of course, this is still experimental.

深空失忆 2024-10-16 17:06:49

您可以尝试使用 imagemagick 的 montage 命令来创建单个图像。

You could try the montage command of imagemagick to create a single image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文