0

Does the order of javascript files affect the actual speed of the scripts? I am thinking that maybe the browser would be able to read first the scripts in the first file like if you have 5 js files like this:

<script src="jsfile1.js"></script>
<script src="jsfile2.js"></script>
<script src="jsfile3.js"></script>
<script src="jsfile4.js"></script>
<script src="jsfile5.js"></script>

and for testing, if I have the function, say:

function retrieve_ajax_data_then_render_page(){
    //some functions
}

would it be faster for the browser to execute the function if it is in jsfile1.js? or everything will be hoisted at the same level once the browser has parsed the js files? Thanks!

  • Declaration of the function itself wouldn't matter in terms of execution. If it is about calling the functions, yes. The order in which they are included in the html matters. – cSharp Jun 22 '22 at 04:55
  • Your browser will download all of those scripts in parallel, and begin executing them sequentially in the order in which they appear, top-down. Function calls in `file1.js` will execute before function calls in `file5.js`. – user229044 Jun 22 '22 at 04:59

0 Answers0