简体   繁体   English

弹出窗口的数量是否会影响页面加载速度?

[英]Does the number of popovers affect page load speed?

I have a page with possibly 2000 popovers using bootstrap 4. 我有一个页面,使用引导程序4可能有2000个弹出窗口。

Does the number of popovers affect the page speed? 弹出窗口的数量是否会影响页面速度? I don't know enough about javascript frameworks to understand whether loading 10 popovers has the same effect as loading 2000. That is what I want to understand. 我对javascript框架了解不足,无法了解加载10个弹出窗口是否与加载2000年具有相同的效果。这就是我想了解的内容。

The contents of the popovers is loaded by javascript. 弹出窗口的内容由javascript加载。

One method I have used to minimize the impact of things like this is to use a single popover/modal/dialog/etc.. and then changed it's contents right before it is shown. 我用来最小化此类影响的一种方法是使用单个popover / modal / dialog / etc ..,然后在显示之前立即更改其内容。 This way you don't have 2k extra elements in the DOM that 99% of the time are doing nothing. 这样,您就不会在DOM中有2k多余的元素,而有99%的时间什么也不做。

I worked up an example of bootstrap popover's using the selector option and delegation by enabling it on a parent element. 我使用了selector选项并通过在父元素上启用它来创建了一个自举弹出窗口的示例。 It appears that they may have any overhead issues worked out. 看来他们可能解决了所有开销问题。

If you inspect the body of the example, you will see a single popover div appended to the body when it is shown and then removed when it hidden. 如果检查示例的主体,则将在显示时在主体上看到一个弹出框div,然后在隐藏时将其删除。

 $(function() { var $table = $('#test'); for(var i = 0; i < 20; i++) { var row = $('<tr />'); for(var j = 0; j < 100; j++) { var td = $('<td />').attr({id: (i * 100) + j, tabindex: -1}); row.append(td); } $table.append(row); } $table.popover({ html: true, container: 'body', trigger: 'focus', selector: 'td', content: function() { return '<p>This is my id: ' + $(this).attr('id') + '</p>'; } }); }); 
 td { height: 25px; width: 25px; border: 1px solid black; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <table id="test"> </table> 

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

相关问题 将脚本放在网页底部会加快页面加载吗? - Does putting scripts on the bottom of a web page speed up page load? 我将所有内容保存在一个外部.js文件中。 但并非所有功能都在每个页面上使用。 这会影响速度吗? - I keep everything in an external .js file. But not all functions are used on every page. Does this affect speed? 查询字符串似乎会影响页面加载速度 - The query string seems to affect page loading speed 将脚本放在正文后是否有助于页面加载速度? - Does it help page load speed to place script after body? 控制台写入速度是否会影响程序执行速度 - Does console write speed affect speed of program execution 页面加载后在 React 中加载第三方 iframe,使 iframe 不影响 PageSpeed 得分 - Load third party iframe in React after page load, so that the iframe does not affect PageSpeed score 离子2-页面上的多个弹出窗口 - Ionic 2 - multiple popovers on Page JavaScript是否会影响页面源? - Does JavaScript affect the Page Source? 显示:无或可见性:在页面加载时隐藏在body元素上 - 它是否会影响SEO? - Display:none or visibility:hidden on body element on page load - does it affect SEO? 反应路由器会影响页面加载时间吗? - Will react-router affect page load time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM