Load External Scripts With Requirejs Without Access To Config
Solution 1:
The method used in the question does not work because DataTables is AMD-aware. If it detects that there's an AMD-style loader (which RequireJS is), then it defines itself as a module. However, it is invalid for AMD modules to be loaded with <script>
, hence the error message.
The module in forum/admin/footer
should be defined so as to require DataTables:
define([...,
'//cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/jquery.dataTables.min.js'],
function (...) {
});
(There's no need for a parameter corresponding to the DataTables module since it is a jQuery plugin.)
A few additional notes regarding the wider issue of integrating this plugin in a site that has already configured RequireJS:
require.config
could be called multiple times to add configuration. However this may be deemed unacceptable if no coordination is expected between the plugin and the main code.RequireJS has a notion of context. The documentation talks about it for loading multiple versions but maybe it can be fruitfully adapted to allow a plugin-specific configuration.
Solution 2:
Have you just tried a simple:
require(['//cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/jquery.dataTables.min.js']);
It works for local files without a doubt.
Post a Comment for "Load External Scripts With Requirejs Without Access To Config"