Repeating website background image - size vs speed

前端 未结 7 1485
滥情空心
滥情空心 2020-12-09 08:57

I was wondering if anyone has done any tests with background images. We normally create a background that repeats at least in one direction (x or y or both).

相关标签:
7条回答
  • 2020-12-09 09:07

    I'd put money on the bottleneck being the image download rather than the rendering engine doing the tiling, so go for the 1 pixel wide option.

    Also the 24-bit PNG is redundant since you're still only getting 8 bits per channel (red, green and blue).

    0 讨论(0)
  • 2020-12-09 09:12

    The rendering speed is the bottleneck here, since bigger tiles can be put into the browser's cache.

    I've actually tried this for the major browsers, and at least some of them rendered noticeably slow on very small tiles.

    So if increasing the bitmap size does not result in ridiculously big file sizes, I would definately go with that. Test it yourself and see. (Remember to include IE6, as still many people are stuck with it).

    You might be able to strike a good balance between bitmap size and file size, but in general I'd try 50x400, 100x400, 200x400 and even 400x400 pixels.

    0 讨论(0)
  • 2020-12-09 09:15

    I found out that there may be a huge difference in the rendering performance of the browser, if you have a background-image with width of 1px and repeating it. It's better to have a background-image with slightly larger dimensions. So a image with a width of 100px performs much better in the browser. This especially comes into play when you use a repeated background-image in a draggable layer on your website. The drag-performance is pretty bad with an often-repeated background-image.

    0 讨论(0)
  • 2020-12-09 09:16

    I have not benchmarked this but I'd bet that on most modern computers the rendering won't be an issue whereas you always want to save on on the image download time. I often go for the 1px type of graphics.

    0 讨论(0)
  • 2020-12-09 09:22

    I generally prefer to go in between, 1pixel wide will probably make your gradient seem a bit unclear but you can do something like 5pixel width which gives enough room to the gradient to maintain consistency and clarity across the page.. but I would suggest you can add more patterns and images to a single image and then use background positioning(css sprites) to position them because download a single image of say 50kb would take less time comapared to 5 40kb images since the browser makes fewer requests to the server...

    0 讨论(0)
  • 2020-12-09 09:32

    I'd like to point out that for the cost of sending down an extra few rows (1-2 only example here) .8k - 1.6kb (if you can get away with 8-bit) more like 2.4kb - 4.0kb for 24bit

    2 pixel columns more means the required iterations required to blit the background in is cut down to 1/3 for up to 1.6kb (8-bit) or 4kb (24bit)

    even 1 extra column halves the blitting required down to half the element width.

    If the background's done in less than a second for a 56.6k modem I reckon it's lean enough.

    0 讨论(0)
提交回复
热议问题