Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out your code:<br> Everytime you're doing an Ajax Request you're doing this:</p> <pre><code>$table .find('tbody') .html('') .append(data); $table.trigger("update", [true]); </code></pre> <p>To explain what it does :</p> <ol> <li>you call <code>$.find</code> on a html tag (slow)</li> <li>you remove the content of the table (causes the browser to repaint the pixels in white)</li> <li>you ask the Browser's DOM to parse a whole html table causing multiple layout reprocessing and repaints (critically bad)</li> <li>calling trigger on the table (ok)</li> </ol> <p>I think that just by processing your data better can speed up your process countless times depending on the size of your table. Consider this:</p> <pre><code>// I should be put at the top of the file (not in an Ajax Loop) window.compileHTML = function (html) { var div = document.createElement("div"); div.innerHTML = html; var fragment = document.createDocumentFragment(); while ( div.firstChild ) { fragment.appendChild( div.firstChild ); } return fragment }; //Keeping a reference variable to var $tableContents = $table.find('tbody') //When ajax is done var compiledHtml = window.compileHTML(data); $tableContents.html(compiledHtml); $table.trigger("update", [true]); </code></pre> <p>Edit: If <code>compileHTML</code> doesn't work. A nice way of doing almost the same thing (but without compiling) would be to do:</p> <pre><code>//put just after $table declaration var $tableContents = $table.find('tbody') //When ajax is done var $html = $('&lt;tbody/&gt;').html(data); $tableContents.replaceWith($html) $table.trigger("update", [true]); </code></pre> <p>Edit:</p> <p>What I did was creating a document fragment (outside of DOM), let the html processing via <code>compileHTML</code> not have any incidence on the current page. And when all is done. Appending only the root of the new dom tree created to the DOM, causing only one repaint against: "as many as there is cells and rows" will cause your browser to look more stable.</p> <p>Optional (not totally): There is probably more pitfalls on your code, but investigating performances is hard. I would recommend doing a timeline check on <a href="https://developers.google.com/chrome-developer-tools/" rel="nofollow">Chrome/Firebug</a> -> open console (<kbd>F12</kbd> or <kbd>Alt</kbd>+<kbd>shift</kbd>+<kbd>i</kbd>) press the "timeline" tab.<br> Press (<kbd>ctrl</kbd>/<kbd>cmd</kbd>)+<kbd>E</kbd> and let and update pass , repress <kbd>ctrl</kbd>+<kbd>E</kbd> and you'll see some histogram chart, the bigger bars mean your app is laggy/janky, you can then click on the bar to see the stack trace of all the function called and thus be optimized.<br> Hope that helps :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload