T
T
TheMafia2014-03-07 11:10:08
JavaScript
TheMafia, 2014-03-07 11:10:08

Does requirejs speed up script loading times?

Hello! I recently started getting familiar with require.js. AMD - asynchrony. In my understanding, this implies independent loading of modules (js scripts). In other words, parallel. But here's what I saw in chrome dev tools:
With the usual connection of scripts in the footer:

<script type="text/javascript" src="templates/js/new/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="templates/js/new/eventTrackerManager.v.1.0.js"></script>
<script type="text/javascript" src="templates/js/new/constants.js"></script>
<script type="text/javascript" src="templates/js/new/utils.js"></script>

In CDT:
SQ82z.png
When included via require.js:
require.config({
    baseUrl: "templates/js/new/",
    paths: {
        "jQuery": "lib/jquery-2.0.3.min",
        "jQueryUI" : "lib/jquery-ui-1.10.3.custom.min",
        "Utils" : "modules/utils",
        "contactform" : "modules/contactform"
                ...
    },
    shim: {
        "jQueryUI": {
            exports: "$",
            deps: ['jQuery']
        }
    }
});
require(["contactform"], function(CF) {
    CF.init();
});

Lavqw.png
In the first case, the browser loads all the scripts in parallel, then executes them in the connection order.
In the second case, the scripts are connected sequentially, which takes more time.
But! In the first case, when hovering over the script loading bars, the blocking property is very large, and in the second, it is small. Does this mean that downloading scripts via AMD does not block further page loading? Or what is the benefit of using AMD then, other than organizing code and establishing dependencies?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rumkin, 2014-03-07
@TheMafia

requirejs works in the same way in parallel, but it loads dependent scripts after it executes the next script and finds out what needs to be loaded next. In order to avoid this, various techniques are used, such as precompilation. Read more here habrahabr.ru/post/181536/.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question