# External scripts If we have a lot of JavaScript code, it can be put into a separate file. The script file is attached to HTML like this: ```html ``` Here `/path/to/script.js` is an absolute path to the file with the script (from the site root). We can give a full URL too, for instance: ```html ``` It is also possible to provide a path relative to the current page. For instance, `src="lodash.js"` means a file from the current folder. To attach several scripts, use multiple tags: ```html … ``` [smart] As a rule, only simplest scripts are put into HTML. More complex ones reside in separate files. The benefit is that the browser will download it only once, and then store in its [cache](https://en.wikipedia.org/wiki/Web_cache). After it, other pages which want the same script will take it from the cache instead of downloading it. So the file is actually downloaded only once. That saves traffic and makes the future pages faster. [/smart] [warn header="If `src` is set, the script content is ignored."] A single ` ``` One needs to choose: either ` ``` [/warn] ## Asynchronous scripts: defer/async Browser loads and shows HTML gradually as it comes. That's clearly noticeable on the slow internet connection. The browser doesn't wait for the page to load fully. It shows the part that has been loaded already, and then adds content to it as it loads. When the browser meets a ` */!*
Rabbits counted!