Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Should I always put my JavaScript file in the head tag of my HTML file?
You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the <head> tag or <body> tag.
It’s good for performance to add JavaScript in <body> element. Here’s an example to add <script> under <body>…</body> −
<html>
<body>
<script>
<!--
document.write("Hello World!")
//-->
</script>
</body>
</html>
Here’s an example to add <script> under <head>…</head> −
<html>
<head>
<script>
<!--
document.write("Hello World!")
//-->
</script>
</head>
<body>
</body>
</html>Advertisements