2

I'm curious if it is possible to add the .js using in Google Chrome console, so the code is executed in between the list of loaded .js files.

As result, when the page is loaded, there are some .js files that are loaded from top to the bottom.

<script src="js1.js" type="text/javascript"></script>
<script src="js2.js" type="text/javascript"></script>

I want to load it in this order:

<script src="js1.js" type="text/javascript"></script>
<script src="js_from_console.js" type="text/javascript"></script>
<script src="js2.js" type="text/javascript"></script>

Is it possible?

CodeTrooper
  • 1,890
  • 6
  • 32
  • 54
Haradzieniec
  • 9,086
  • 31
  • 117
  • 212
  • What do you mean by 'to add the `.js` using in Google Chrome console'? If you are able to edit the html code why not add the console code directly. – angabriel Dec 26 '13 at 11:15
  • I'm not able to change the order of loaded .js files and I'm not able to modify the head of the html file. However, I'd like to know (to test) the behavior of the page what if I add the js file to the header in between other scripts (the order counts because of conflicts). And I'm asking if it is possible to test it using console. – Haradzieniec Dec 26 '13 at 11:38
  • Hmm have you tried setting a breakpoint at the very end of the first script and then execute your console code? Maybe this doesnt work on an active breakpoint, did not try that before. – angabriel Dec 26 '13 at 11:41

2 Answers2

0

Javascript files loaded in the head section should load sequentially and block until each has finished loading, so you can do

<html>
<head>
   <script src="js1.js" type="text/javascript"></script>
   <script src="js_from_console.js" type="text/javascript"></script>
   <script src="js2.js" type="text/javascript"></script>
</head>
</html>

Is this what you are looking for?

Or you go with head.js

<script src="//cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.min.js"></script>    

<script>
  head.load("js1.js", function() {
    console.log("js1.js has loaded. js2.js loads after I have done my stuff now");

    // do it

    head.load("js2.js");
  });
</script>
angabriel
  • 4,979
  • 2
  • 35
  • 37
  • I'm not able to modify the . And I would like to test what if I add let's say my js file to the head. I can execute the code in the console, but the order counts. – Haradzieniec Dec 26 '13 at 11:41
0

Son ? Google is our best friend :). and here is your answer:

https://stackoverflow.com/a/19348/539075

Community
  • 1
  • 1
0bserver07
  • 3,390
  • 1
  • 28
  • 56