简体   繁体   English

jQuery的remove()函数是否会取消元素的请求

[英]Will jQuery's remove() function cancel the request of the element

I'm wondering if jQuery's remove() function will reliably cancel requests that have been triggered during page load. 我想知道jQuery的remove()函数是否可以可靠地取消页面加载期间触发的请求。 Given following setup: 给定以下设置:

<video>
  <source src="movie1.mp4" type="video/mp4">
</video>

<video>
  <source src="movie2.mp4" type="video/mp4">
</video>

and they are quite big videos to return in the response (~40mb). 并且它们是相当大的视频,可以在响应中返回(〜40mb)。

When I have this in my JS: 当我在JS中有此代码时:

$(document).ready(isMobile);

function isMobile() {
  // condition that checks for mobile device here, next line executed if true
  $('video').remove(); 
};

will the video already requested still be loaded? 是否仍会加载已请求的视频? Will any of the videos be loaded? 是否会加载任何视频?

As you can assume this is about cancelling unnecessary loading of videos which wouldn't be displayed for mobile anyway. 您可以假设这是关于取消不必要的视频加载,而这些视频无论如何都不会显示在移动设备上。

After running the following snippet, I noticed that it did indeed stop downloading the file after the current "chunk" finished downloading. 运行以下代码段后,我注意到在当前“块”完成下载后,确实确实停止了文件的下载。 This would prevent further loading by large sources. 这将防止大量源进一步加载。

 $(document).ready(function() { setTimeout(function() { $('video').remove(); }, 10000); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <video src="https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_30mb.mp4" type="video/mp4" controls> 

And after downloading/stopping 10 seconds in (The chunk finished downloading, and then stopped downloading more data): 在下载/停止10秒后(该块完成下载,然后停止下载更多数据):

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

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