Using getScript in main.js file to reduce load size

Does it make sense to use $.getScript();in jQuery to do something like the following:

$("#action-one").click(function() {     
    $.getScript('scripts/action-one.js');
});

$("#action-two").click(function() {     
    $.getScript('scripts/action-two.js');
});

Will it reduce the size of the main.js file, which will speed up the loading time? Also means that the code only ever loads if it is used, it can occur in problems if the same code loads again and again, though ..

(I do not do this at the moment, but it just crossed my mind if you have very large js files)

+3
source share
1 answer

, . , , , .

- , , , , , .

, . , . , - .

, , , , , .

+4