An external style sheet and external JavaScript file are used to define the various styles and actions respectively while keeping everything centralized. This is a best practice because if you were to place your scripts and styles directly in the head
of each document, there would be no centralized location to make your changes and you’d have to search for all the various rules across multiple locations. See Placing Styles and Scripts Directly in a Document for more information.
The following shows where to place our links to our external script file(s) and CSS file(s). Typically this is done directly after the title
tag, but could be placed anywhere in the head
of the document.
Advanced HTML Template
The link
tag is used to link to external style sheets. The type attribute tells the browser what kind of document to expect and the href attribute is the target URL for where the document lives.
Similarly, the script
tag is used to link to an external JavaScript file, and requires the type attribute to tell the browser to expect JavaScript and the src attribute which tells the browser where the document lives in the file structure.
Non-Crucial Scripts
Non-crucial scripts can be placed just before the closing /body
tag which can speed up the page load time because the page can first render before applying the scripts.