pr193
Computer-Programmer
External scripts and how to connect them adrenaline-studios.com
If there is a lot of JavaScript code - it is taken out in a separate file, which
plugged in HTML:
& lt; script src = & quot; /path/to/script.js" & gt; & lt; / script & gt;
Here /path/to/script.js is the absolute path to the file containing the script (from
site root).
The browser will download the script and execute it.
You can also specify the full URL, for example:
& lt; script
src = & quot; https: //cdnjs.cloudflare.com/ajax/libs/lodash.js/4.3.0/lodash.js" & gt; & lt; / scri
pt & gt;
You can also use the path relative to the current page. For example,
src = & quot; lodash.js & quot; denotes a file from the current directory.
To connect multiple scripts, use several tags:
& lt; script src = & quot; /js/script1.js" & gt; & lt; / script & gt;
& lt; script src = & quot; /js/script2.js" & gt; & lt; / script & gt;
...
On a note:
As a rule, only the simplest scripts are written in HTML, and complex ones are written in
separate file.
The browser only downloads it for the first time and later on, if it is correct
setting up the server, it will take from its cache.
Thanks to this, the same large script containing, for example,
function library, can be used on different pages without full
reboots from the server.
If the src attribute is specified, then the contents of the tag are ignored.
In one SCRIPT tag, you cannot simultaneously connect an external script and specify
code.
Computer-Programmer
External scripts and how to connect them adrenaline-studios.com
If there is a lot of JavaScript code - it is taken out in a separate file, which
plugged in HTML:
& lt; script src = & quot; /path/to/script.js" & gt; & lt; / script & gt;
Here /path/to/script.js is the absolute path to the file containing the script (from
site root).
The browser will download the script and execute it.
You can also specify the full URL, for example:
& lt; script
src = & quot; https: //cdnjs.cloudflare.com/ajax/libs/lodash.js/4.3.0/lodash.js" & gt; & lt; / scri
pt & gt;
You can also use the path relative to the current page. For example,
src = & quot; lodash.js & quot; denotes a file from the current directory.
To connect multiple scripts, use several tags:
& lt; script src = & quot; /js/script1.js" & gt; & lt; / script & gt;
& lt; script src = & quot; /js/script2.js" & gt; & lt; / script & gt;
...
On a note:
As a rule, only the simplest scripts are written in HTML, and complex ones are written in
separate file.
The browser only downloads it for the first time and later on, if it is correct
setting up the server, it will take from its cache.
Thanks to this, the same large script containing, for example,
function library, can be used on different pages without full
reboots from the server.
If the src attribute is specified, then the contents of the tag are ignored.
In one SCRIPT tag, you cannot simultaneously connect an external script and specify
code.