-1

I have my .css already linked. Cant find how to also link .js propely.

<html>

    <head>
        <title>Final</title>
        <link rel="stylesheet" type="text/css" href="final.css">
    </head>

    <body>
    </body>

</html>
Sotirios Delimanolis
  • 252,278
  • 54
  • 635
  • 683

3 Answers3

2

By use of the script tag. (MDN Reference)

<script src="filename.js" type="text/javascript"></script>

The above is the simple, short answer.

Standard practice tends to be, for most JavaScript, to place the script tag at the bottom of the body or to 'defer' it in the head. This is so that the loading of JavaScript does not slow the page itself from loading. To do either of these, see the following:

<head>
    <!-- OTHER HTML STUFF! -->

    <!-- This particular script will be deferred after document parsing. -->
    <script src="filename.js" type="text/javascript" defer></script>
</head>
<body>
    <!-- STRUCTURE AND SUCH OF PAGE -->

    <!-- This particular script will load after the body. -->
    <script src="filename.js" type="text/javascript"></script>
</body>

There are more strategies with their own advantages and disadvantages, and it's a deeper topic, but the above basics should be good as a standard practice.

An excellent and concise summary of the topic can be seen here.

1

The <script> tag (reference):

<script src="filename.js" type="text/javascript"></script>
Droppy
  • 9,470
  • 1
  • 18
  • 27
0
<script type=“text/javascript" src="filename.js"></script>
Ryan
  • 684
  • 8
  • 14