图像预加载会阻止额外的服务器请求吗?

发布于 2024-09-19 07:44:53 字数 412 浏览 3 评论 0 原文

我目前无法实时测试,所以我问:
如果此脚本正忙于从数组(例如,几 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];
  }
}

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

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

发布评论

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

评论(1

因为看清所以看轻 2024-09-26 07:44:53

浏览器只会在同一域上并行运行一定数量的请求。该数字因浏览器而异。因此,您通常会期望看到更多请求在最后排队。

在某种程度上解决这个问题的一种方法是在与其他图像不同的域上预加载图像,因为浏览器将并行加载来自不同域的请求。

因此,如果您从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.

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