我目前无法实时测试,所以我问:
如果此脚本正忙于从数组(例如,几 MB)加载图像,并且用户恰好执行某些需要尚未加载的图像之一的行为,那么其加载是否会延迟?或者浏览器可以发出并行请求吗?
函数 preloadImg()
{
var args = simplePreload.arguments;
document.imageArray = new Array(args.length);
for(var i=0; i
I can't test this live at the moment, so I'm asking:
If this script is busy loading images from an array (say, a few MB worth), and the user happens to perform some behavior that requires one of the images that has not yet loaded, will its loading be delayed? Or can the browser send out parallel requests?
function preloadImg()
{
var args = simplePreload.arguments;
document.imageArray = new Array(args.length);
for(var i=0; i<args.length; i++)
{
document.imageArray[i] = new Image;
document.imageArray[i].src = args[i];
}
}
发布评论
评论(1)
浏览器只会在同一域上并行运行一定数量的请求。该数字因浏览器而异。因此,您通常会期望看到更多请求在最后排队。
在某种程度上解决这个问题的一种方法是在与其他图像不同的域上预加载图像,因为浏览器将并行加载来自不同域的请求。
因此,如果您从domaina.com 最多并行预加载8 个图像,您仍然可以同时加载domainb.com 上的命令可能需要的图像。这可以帮助您解决并行加载问题。
我想您仍然想在一些浏览器中测试您的特定问题,但我希望这会有所帮助。
Browsers will only run so many requests in parallel on the same domain. The number varies between browsers. So you would typically expect to see additional requests get queued at the end.
One way to get around this to some extent is to have your preload images on a different domain than the other images since browsers will to load requests from different domains in parallel.
So if you are preloading 8 images in parallel maximum from domaina.com you could still have the images that might be needed on command on domainb.com loading at the same time. That could help you with the parallel loading issues.
I imagine you will still want to test your particular issues out in a few browsers, but I hope this will be helpful.