Answer the question
In order to leave comments, you need to log in
What would you recommend for dynamically loading JS and CSS module files?
I wanted to use yepnope, but... https://github.com/SlexAxton/yepnope.js#deprecatio...
Started tinkering with RequireJS, but there's trouble... requirejs.org/docs/faq-advanced.html#css
What do you advise?
Answer the question
In order to leave comments, you need to log in
Look towards stealjs in the javascriptmvc package . Works very fast and groups files pretty cool. In most situations, even when several dependencies need to be loaded, they will be loaded as 1 file. In general, try it, everything is very cool there.
I advise you to abandon the idea of dynamic css loading.
In general, all these amd / commonjs were not invented for dynamic loading of modules, but for dividing the project and explicitly specifying dependencies. Just convenient at the time of development. Although then it's better to use ES6 + compilation to ES5.
For JS - RequireJS
For CSS similar code in index.html:
<script>
function createLink(src){
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = src + '?v=' + SYSTEM.cssVersion;
document.querySelector("head").appendChild(link);
}
createLink('css/main.css');
createLink('vendor/select2/dist/css/select2.css');
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question