C
C
Cat Anton2014-10-11 14:47:19
css
Cat Anton, 2014-10-11 14:47:19

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

3 answer(s)
A
Alexander Zelenin, 2014-10-11
@27cm

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.

S
Sergey, 2014-10-11
Protko @Fesor

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.

A
Alexey, 2015-06-10
@Murmurianez

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>

The bottom line is: you insert into the HTML itself with the CSS necessary to render the first page, the rest of the CSS will start loading only after the page is completely rendered - without rendering blocking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question