4 ms·
lib you linked is a bit crazy, it uses setInterval to guess when a css is properly loaded/applied and delays running dependent code imho this is sufficient:
by emergie 9y ago
lib you linked is a bit crazy, it uses setInterval to guess when a css is properly loaded/applied and delays running dependent code
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
});
- hdhzy 9y agoYou don't need to guess, you can check document.styleSheets if it contains your file. See: https://curiosity-driven.org/minimal-loader#plugins https://curiosity-driven.org/minimal-loader#plugins