按特定顺序下载图像 [英] download images in specific order
问题描述
我正在实现一个显示产品360度视图的功能。该视图由从服务器下载的一系列独立图像表示。
I am implementing a feature that displays a 360 degree view of a product. The view is represented by a sequence of stand alone images that are downloaded from the server.
从用户体验的角度来看,序列中的一些图像更多比其他人重要。因此,当我的代码下载图像时,我想首先获取重要的图像并立即显示它们,然后获取不太重要的图像。
From the point of view of the user experience, some images in the sequence are more important than the others. So when my code downloads images I would like to fetch the important ones first and display them immediately, and then fetch less important ones.
我知道我可以订购我的图像通过它们的重要性,一个接一个地顺序下载它们,但我想利用异步下载来减少带宽。
I know that I can order my images by their importance and download them sequentially, one after another, but I would like to take advantage of asynchronous downloading to reduce the bandwidth too.
任何人都可以在这推荐任何东西吗? / p>
Can anyone recommend anything here?
推荐答案
你可以在第一波中加载最重要的图像,然后像这样加载其他图像:
You can load the most important images in a first wave and then the other ones like this :
var firstImages = [];
var otherImages = [];
var count = firstImages.length;
var onloadfirstwave = function() {
if (--count==0) {
// lauches second wave
}
};
// and for each image, do
firstImages[i].onload = onloadfirstwave;
firstImages[i].src = "someurl";
只有在第一批图像加载后才会启动第二波,并且第一次加载的并行性将会出现保留。
The second wave would be launched only after the first images are loaded and the parallelism of those first load would be preserved.
这篇关于按特定顺序下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!