Closed mbvyd closed 5 years ago
You can do a custom insert using the before
callback:
loadjs(['/path/to/foo.js', '/path/to/bar.css'], {
success: function() {},
error: function(pathsNotFound) {},
before: function(path, scriptEl) {
if (path === '/path/to/foo.js') {
document.body.appendChild(scriptEl);
return false; // return false to bypass default DOM insertion mechanism
}
}
});
Thanks, i missed this
(Almost) same feature which has https://github.com/filamentgroup/loadCSS ("Function API" section, "before" param).
Possible use case: In head section may be placed call to loadjs to load external CSS (example below). At the same time may be needed to load bunch of js, which should be loaded and applied synchronously. And it is more than ok to place them before
</body>
.Of course, it is possible to exclude those scripts from processing by loadjs. But with control of where (when) to load elements we could manage all stuff in one control script: