简体   繁体   English

从DOM中删除尚未完全加载的图像:传输中止了吗?

[英]Removing from the DOM an image not yet fully loaded: is transmission aborted?

An image (not cached) is added to the DOM; 将图像(未缓存)添加到DOM; for example (using jQuery): 例如(使用jQuery):

$('#hereItGoes').append('<img id="theImage" src="image.jpg" />');

The browser starts downloading the resource, it takes some time... 浏览器开始下载资源,需要一些时间......

Before the image is fully loaded some kind of event triggers a callback that removes the image. 在图像完全加载之前,某种事件会触发删除图像的回调。

$('#theImage').remove();

Is the image resource transmission aborted? 图像资源传输是否中止?

More specifically, does this stop the server from sending (image) data? 更具体地说, 这是否会阻止服务器发送(图像)数据?


To give some "context" to the question: 为这个问题提供一些“背景”:

a long scrolling page is often designed to lazy-load images: only when images enter the viewport are loaded; 长滚动页面通常设计为延迟加载图像:仅当图像进入视口时才加载; as each of them is ready then is faded in and displayed to the user. 当它们中的每一个都准备就绪时,它就会淡入并显示给用户。

Now what if the user scrolls down the page quickly? 现在如果用户快速向下滚动页面怎么办?

It may occurr the situation where many images enter the viewport (and start being downloaded) but exit before they're ready. 可能会出现许多图像进入视口(并开始下载)但在准备好之前退出的情况。

Keeping loading would waste bandwidth (and server resources). 保持加载会浪费带宽(和服务器资源)。

No, this is not possible. 不,这是不可能的。 This is because once you request a resource, it is requested asynchronously by your client-side code so that it won't block the rest of your DOM from loading. 这是因为一旦您请求资源,客户端代码就会异步请求它,这样它就不会阻止其他DOM加载。

In a more complex server side request, another client-side message can be sent to stop the server from continually processing the data for the response, but in the event that this is sending back an image, there's no point in trying to stop it. 在更复杂的服务器端请求中,可以发送另一个客户端消息以阻止服务器不断处理响应的数据,但是如果这是发回图像,则尝试停止它是没有意义的。

This will have not hurt client-side DOM performance though, since you'll just be ignoring the server response. 这不会损害客户端DOM性能,因为您只是忽略了服务器响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM