dataTables loads slow with requireJS

dataTables loads slow with requireJS

NewcomaNewcoma Posts: 24Questions: 0Answers: 0
edited December 2013 in General
When I use requireJS to load dataTables I see the unprocessed html for a short moment. Maybe because it waits for the DOM to be loaded ?

How can I load dataTables faster with requireJS ?

This is the main file

require.config({
paths: {
'jquery': 'libs/jQuery-2-0-3',
'datatables-plugin': 'plugins/jquery-datatables'
}
});

require(['jquery','datatables-plugin'],
function($) {
'use strict';

$(document).ready(function() {

$('.tablesorter-js').dataTable();

});
});

And the html in the head tag.

Replies

  • NewcomaNewcoma Posts: 24Questions: 0Answers: 0
    As an example I call the scripts in the head tag without requireJS the datatable is executed right away.




    and end of body tag


    $('.tablesorter-js').dataTable();
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'm afraid I don't know how require is loading the Javascript - is it adding the defer tag? It might be best to ask in a require.js based forum what is happening.

    Allan
  • NewcomaNewcoma Posts: 24Questions: 0Answers: 0
    I solved it by changing

    require(['jquery','datatables-plugin'],

    to

    define(['jquery','datatables-plugin'],

    Removed the

    $(document).ready(function() {

    And positioned the



    At the end of the body tag.
This discussion has been closed.