简体   繁体   English

可以采取哪些措施来提高大型数据集的IE8性能?

[英]What can be done to improve IE8 performance for large sets of data?

I have a page which displays ~300 pages worth of tabular data. 我有一个显示约300页表格数据的页面。 Firefox, Chrome, Safari all work fine but IE 7, 8, and 8 Compatibility view all wretch. Firefox,Chrome,Safari都运行良好,但IE 7,8和8兼容性视图都很糟糕。 It lags for several seconds when I try to scroll or press the page up/page down button. 当我尝试滚动或按下向上翻页/向下翻页按钮时,它会滞后几秒钟。

Pagination, smaller data sets, and other usability suggestions will not work for this page. 分页,较小的数据集和其他可用性建议不适用于此页面。 Assume I absolutely have no choice but to display all this data at once... what are some things I can do to tweak it? 假设我绝对别无选择,只能一次显示所有这些数据......我可以做些什么来调整它?

The data is being loaded via jQuery/Ajax and that seems to be at least in part suspect here, because when I created a test page to render the results directly it isn't quite as slow, but still not nearly as snappy as other browsers. 数据正在通过jQuery / Ajax加载,这似乎至少在某种程度上是可疑的,因为当我创建一个测试页面来直接渲染结果时,它并不是那么慢,但仍然不像其他浏览器那样快速。

I've successfully used jQuery plugins such as SlickGrid to tackle similar problems in the past, but for reasons that would take a long time to explain they are not an option, even with the micro template rendering capabilities. 我已经成功地使用了像SlickGrid这样的jQuery插件来解决过去类似的问题,但是由于原因需要很长时间来解释它们不是一个选项,即使使用微模板渲染功能也是如此。 I'm mainly concerned with what tweaks I can make to improve performance without reworking the entire page or introducing third party solutions. 我主要关注的是我可以在不重新整理页面或引入第三方解决方案的情况下进行调整以提高性能。

Is a simplified DOM going to make a big difference? 简化的DOM会有很大的不同吗? Or does IE not handle data brought in via JavaScript/Ajax well? 或者IE不能很好地处理通过JavaScript / Ajax带来的数据?

Difficult to see without more details or an example... how are you building the content? 没有更多细节或示例很难看到......你是如何构建内容的? There are quite a few little catches with building table content: in particular setting innerHTML directly on <table> doesn't work in IE, so jQuery's html() will probably be doing it a long, slow way round if that's what you're using. 构建表内容有很多小问题:特别是在<table>上直接设置innerHTML在IE中不起作用,所以jQuery的html()可能会做很长很慢的事情,如果这就是你的意思使用。

But a general-purpose tip for anything with tables, especially larger ones: set the style table-layout: fixed on the <table> element, setting column width styles on either the first row of cells only, or on a set of <col> ​s. 但是对于任何带有表的东西的通用提示,尤其是更大的表:设置样式table-layout: fixed<table>元素上,仅在第一行单元格上设置列width样式,或者在<col>的集合上设置列width样式<col> s。 (Columns without an explicit width will share the remaining width equally between them in a liquid layout situation.) (没有明确width列将在液体布局情况下共享它们之间的剩余宽度。)

Since it does not depend on the quantity of content in each cell, fixed table layout is faster and much more predictable than the default auto table layout algorithm. 由于它不依赖于每个单元格中的内容数量,因此fixed表格布局比默认auto表格布局算法更快且更可预测。

use innerHTML and minimise js / dom interaction. 使用innerHTML并最小化js / dom交互。 Js isn't that slow in IE but the js/dom bridge is very slow. Js在IE中并不慢,但js / dom桥非常慢。 Also avoid to select elements in the html you are about to insert. 还要避免在要插入的html中选择元素。 If you do so, jQuery will have to walk through each element and test against the id or css attribute. 如果你这样做,jQuery必须遍历每个元素并针对id或css属性进行测试。 This is very slow. 这很慢。

In itself inserting a few thousands elements in the DOM in IE is doable. 本身在IE中插入几千个元素是可行的。 but if you start doing some changes on this html, you may runs into severe perf issues. 但是如果你开始对这个html进行一些更改,你可能会遇到严重的性能问题。

Beyond that, your code is needed in order to tell how to make it faster. 除此之外,您需要使用代码来说明如何加快速度。 also a test page that can be profiled would be great. 还有一个可以分析的测试页面会很棒。

FYI, the only performance profiling tool available for IE is dynatrace ajax version. 仅供参考,唯一可用于IE的性能分析工具是dynatrace ajax版本。 Its free and an excellent quality software. 它免费和优质的软件。 Use it ! 用它 !

   1. Avoid using script that going to make changes in DOM specially inside a loop.
        eg.

for ( var i = 0; i < rownodes.length; i++) {
  curRow = document.createElement("tr"); // this is a direct operation to DOM
  for(j=0 ;j <colLenth;j==){ 
     cell = document.createElement("td");
   }
}
// instead use..
var table = '<table>';
for ( var i = 0; i < rownodes.length; i++) {
   table = table + '<tr>'; // don't use DOM operation if not needed.
    for(j=0 ;j <colLenth;j==){   
      table = table + '<td> my text </td>';
    }
}
table = table + '</table>';// simple string operations will be much faster
('#myDiv').append($(table));// at the end you can add it to the DOM. 

[Building High Performance HTML Pages][1]

  [1]: http://msdn.microsoft.com/en-us/library/ms533002%28v=vs.85%29.aspx

I've found that when you're dynamically inserting large, complex content into an existing page, IE is much (much) faster at setting innerHTML than at programmatically creating dozens or hundreds of DOM nodes and inserting them, whether you're using a client-side library or not. 我发现当你动态地将大型复杂内容插入到现有页面中时,IE在设置innerHTML比在程序上创建数十个或数百个DOM节点并插入它们要快得多(无论你使用的是客户端库是否存在。 If you render your HTML server-side and send it down as a string instead of sending JSON data and rendering client side, you're using more bandwidth, but your IE users will probably have a better experience. 如果您渲染HTML服务器端并将其作为字符串发送而不是发送JSON数据并呈现客户端,那么您将使用更多带宽,但您的IE用户可能会获得更好的体验。

IE's javascript performance is currently pretty terrible, so if you want to make your site faster in IE, minimizing large-scale DOM manipulation is a good start. IE的javascript性能目前非常糟糕,所以如果你想让你的网站在IE中更快,最小化大规模DOM操作是一个好的开始。 It shouldn't be too difficult to make a simple test case for comparison, to see if such a change will benefit your particular situation. 制作一个简单的测试用例进行比较应该不会太难,看看这样的改变是否会对您的特定情况有所帮助。

Watch out for jQuery .find() in IE8. 注意IE8中的jQuery .find()。 If it's not carefully written, you might be causing IE8 to do some pretty ridiculous gymnastics. 如果不仔细写,你可能会导致IE8做一些非常荒谬的体操。 Wish I knew more about why, etc etc but if you comment out your .find() in your jQuery and run it, even though your script is temporarily broken, you might see that the page is suddenly loading quickly. 希望我更了解为什么等等,但如果你在jQuery中注释掉你的.find()并运行它,即使你的脚本暂时中断,你可能会看到页面突然加载很快。

Just a guess, but easy to try. 只是一个猜测,但很容易尝试。

  1. Can also improve your rendering of table by improving it's presentation. 还可以通过改进表格来改进表格的渲染。 by adding colgroup by this the rendering of the table becomes fast(can see the difference when working with large tables) as browser engine doesn't have to look for individual col width's. 通过添加colgroup,表的呈现变得很快(可以看到使用大表时的差异),因为浏览器引擎不必查找单独的col宽度。
  <table style="table-layout: fixed" width="600"> <colgroup> <col width="100"><col width="300"><col width="200"> </colgroup> <tr height="20"> <td>ss</td> <td>ss</td> <td>ss</td> </tr> <tr></tr> .... ... </table> 
see the below link for detailed discription

http://msdn.microsoft.com/en-us/library/ie/ms533002(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/ie/ms533002(v=vs.85).aspx

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

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