34,333
edits
Changes
→= Whether to use inline or external JavaScript
The above example instructs the browser to load the JavaScript from the ''myjscript.js'' file located on the /j-scripts sub-directory of the local web server. It is possible to specify any valid URL here so this could be a file located on any accessible web server if required.
== Whether to use inline or external JavaScript ==
In the section we have looked and both inline and external JavaScript (using the ''src'' argument of the ''<script>'' element. The question now arises as to which is the best approach. The general recommendation is that JavaScript functions should be placed in external ''src'' files wherever possible. The reasoning behind this is that if you have JavaScript code that is used on multiple plages you can modify this code in one place (the external JavaScript file) without having to edit every page that contains the code.