简体   繁体   English

精灵VS大图

[英]Sprites VS Larger Images

While doing some performance testing on my website, I noticed that the 3 images on the home page were taking 1 second per image to load. 在我的网站上进行性能测试时,我注意到主页上的3张图像每张图像要花费1秒的加载时间。

These images are 3 1000 x 1000 high def images that only load on the homepage. 这些图像是仅在首页上加载的3 1000 x 1000高清图像。

I was thinking about turning those 3 into a sprite sheet to reduce the load time of the website. 我当时正在考虑将那3个页面转换为一个精灵表,以减少网站的加载时间。

Do you think this is a good idea? 您认为这是个好主意吗? I know that sprites work well with small images, but I have never tried it with 3 1000px images that are high def. 我知道精灵可以在较小的图像上很好地工作,但是我从未尝试过使用3个高清晰度的1000px图像。

Would if be better to use the sprite or just keep them loaded individually? 使用精灵还是只单独加载它们会更好吗?

I found a few similar questions online but was not able to come to a conclusion. 我在网上发现了一些类似的问题,但无法得出结论。

Good question, the problem that sprites solves is meant mostly when there are many and small images. 好问题,精灵解决的问题主要是在有很多小图像的情况下。 So instead of making 100 requests to a server you make a single one. 因此,您不会向服务器发出100个请求,而是发出一个请求。

When using large images you won't get much benefit from this concept. 当使用大图像时,您将不会从此概念中受益。 Also with larger images, it's better if the first image get's loaded and you could render it to a user and meanwhile load other images. 同样对于较大的图像,最好加载第一张图像,并且可以将其呈现给用户,同时加载其他图像。

Third option would be to render some small thumbnails 20x20 pixels JPG files(usually <~10KB size), and then stretch these to the same size as the larger ones. 第三种选择是渲染一些20x20像素的JPG小缩略图(通常<〜10KB大小),然后将其拉伸到与较大的缩略图相同的大小。 This causes some blurry image but it's understandable what's on the image. 这会导致图像模糊,但是可以理解图像上的内容。 Now when the larger images gets loaded you replace the small ones. 现在,当加载较大的图像时,您将替换较小的图像。 This requires additional JavaScript execution. 这需要额外的JavaScript执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM