A library is imported on a jsp file :
<script type="text/javascript" src="mylibrary.js"></script>
Code is then executed further in the .jsp which requires this library :
<script type="text/javascript">
//various calls take place to myLibrary.js
<script>
I want to extract the javascript functions/function calls into an external .js file. So replace :
<script type="text/javascript">
//various calls take place to myLibrary.js
<script>
with :
<script type="text/javascript" src="newfile.js"></script>
Where ‘newfile.js’ contains the functions/function calls.
Does this mean I will need to import “mylibrary.js” within “newfile.js” ?
What is the import ordering of javascript/jquery ?
No. There is no difference between an inline script and a remote one as far as execution order and scope is concerned.
If a script element containing (or sourcing) a function declaration hasn’t been parsed before you try to call the function, there will be an error.
If you want to call a function defined by jQuery, then you must place the
<script>that loads jQuery before the<script>that loads code which makes the call to the jQuery function.