当页面加载图像时,它只加载一次,还是每次加载标记时? [英] When a page loads an image, does it load it only once, or every time it is found in the markup?

查看:70
本文介绍了当页面加载图像时,它只加载一次,还是每次加载标记时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当页面加载图像时,它只加载一次,还是每次加载标记?那jquery呢,附加一个img会导致它重新加载吗?我问这个是因为我有一个高分辨率的图像,但是你需要在标记的许多实例中使用它。

When a page loads an image, does it load it only once, or every time it is found in the markup? and what about jquery, does appending an img cause it to reload again? I ask this because I have a high res image, but need to you use it in many instances on the markup.

<img src="hello.jpg" />
<img src="hello.jpg" />
<img src="hello.jpg" />


var myimg = $('<img src="hello.jpg />');
$('img').append(myimg);


推荐答案

浏览器每页加载时只加载一次相同的图像,除非你使用积极的反缓存标题(我无法看到你每页加载的原因)。

The browser will load the same image only once per page load, unless you are using aggressive anti caching headers (I can't see a reason why you would per page load).

你可以通过检查网络自己看到这个 Firebug 中的标签。写一个循环并观看网络标签。

You can see this for yourself by examining the net tab in Firebug. Write a loop and watch the net tab.

for (var i = 0; i < 10; i++) {
   var myimg = $('<img src="hello.jpg alt="" />');
   $('img').append(myimg);
}

这篇关于当页面加载图像时,它只加载一次,还是每次加载标记时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆