DataTables Plugins, AMD, and the RequireJS Optimizer

DataTables Plugins, AMD, and the RequireJS Optimizer

segfaultsegfault Posts: 2Questions: 0Answers: 0
edited May 2013 in General
I ran into the exact issue discussed in this StackOverflow thread, except between DataTables v1.9.4 and one its official plugins (Scroller v1.1.0):

http://stackoverflow.com/questions/15371233/unable-to-load-jquery-plugins-when-using-requirejs-r-js-optimizer

Essentially, when loading DataTables as an AMD module via RequireJS (but without using the RequireJS optimizer), things work fine since Scroller can be specified in RequireJS's "shim" configuration (http://requirejs.org/docs/api.html#config-shim), ensuring that DataTables is loaded and evaluated first.

However, once DataTables and Scroller are concatenated into the same file by the optimizer, the evaluation order is wrong even though DataTables appears before Scroller in the output. Scroller starts being evaluated before DataTables itself, since DataTables is loaded as an AMD module but Scroller isn't. Thus, Scroller shows an error dialog saying that DataTables isn't loaded. I'm using several other non-official tiny DataTables plugins related to sorting which also have the same issue.

For now, I've gotten past the issue by patching DataTables to always use browser globals instead of a call to define(), like older versions used to do. However, it would seem that the proper way to fix the issue would be to wrap all DataTables plugins with the same AMD boilerplate that DataTables itself has (and appears in the linked StackOverflow thread) so that DataTables and its plugins are all loaded as AMD modules, preserving proper evaluation order.

My question is this: Is that thinking corrrect? If so, is there any reason that all current versions of the official DataTables plugins have no AMD capbility while DataTables itself does? Is there some other or better way to set things up so that the plugins will load and evaluate in the proper order when concatenated into a single file?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    > the proper way to fix the issue would be to wrap all DataTables plugins with the same AMD boilerplate that DataTables itself has

    Agreed. I just need to get around to doing this! The reason why they don't yet is simply time. I'm slowly making my way through the plug-ins to update them all for the newer DataTables 'standards' (although they only really exist in my head!) with JSDoc comments, Bower version tagging and AMD capability.

    I'll get there - current plan is for it to be along side the v1.10 release, but currently all development effort I can put in is for the core 1.10 work.

    Allan
  • segfaultsegfault Posts: 2Questions: 0Answers: 0
    No worries, thanks for the clarification and for all of your excellent work on DataTables! :)
This discussion has been closed.