by jamescostian · 9y ago · 0 comments
But how is this different from RequireJS? I think RequireJS uses XHR and I don't think it supports CSS, but aside from that, what's new? I feel like this is just reinventing AMD.
As far as I know, requireJS doesn't do XHR requests and evals. That sounds ugly. I think it dynamically injects a script tag and loads the module. I maybe wrong.
Either way, how's it a blocking one?
So, the only thing that makes fetchInject, differ from requireJS is the non-blocking way. Is my understanding correct?
btw you seem to imply that requirejs blocks - what do you mean by that?
imho this is sufficient:
define('css', function () {
return {
load: function (name, parentRequire, onload, config) {
console.log('loading css ' + name);
const link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = name + '.css';
document.getElementsByTagName('head')[0].appendChild(link);
setTimeout(onload, 0);
}
};
});
usage: require(['lib/js/jquery-ui.min', 'css!lib/css/jquery-ui.min'], function () {
// jquery-ui magic goes here
});