EbilGenius
EbilGenius

Reputation: 69

Embed Javascript Files in body tag

I am stuck in a situation where I need to embed a javascript file to a page, but am not able to use the head tags. Is there a way to embed a javascript file without having to use the head tag?

The code I'm using is below (src taken out):

<script type="text/javascript" src="/path/to/file.js"></script>

Any help would be greatly appreciated!

Upvotes: 0

Views: 233

Answers (1)

Nathan
Nathan

Reputation: 7032

You can put a <script> element anywhere, including in the body.

Adding all <script>s to the end of the body is a common practice (to improve load times).

The below is perfectly acceptable:

<html>
    <!DOCTYPE html>
    <head>
        <!--stuff-->
    </head>
    <body>
       <!--stuff-->
       <script type="text/javascript" src="/path/to/file.js"></script>
    </body>
</html>

Upvotes: 2

Related Questions