how to add javascript to html-min

How to add JavaScript to HTML

How to add JavaScript to HTML If you use same JavaScript in different pages, This is not best things to do. You should create an external JavaScript file instead of writing the same script over and over again.

Make a script file and save with .js extension then you can link the external JavaScript file using src attribute in <script> tag.

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

<script> – This tag is used to define a script, such as a JavaScript.
type – specify the type of the script i.e. “text/javascript”
src – script file name and path i.e. “custom.js” with the correct path.

Path May be:

Absolute URL – Refer to another website (src=”https://developerhelps/custom.js”)
Relative URL – Refer to a file within a website (src=”/scripts/custom.js”)

Note: To link a JavaScript file with your HTML, you only have to add the source of the script inside the <body> tag or <head> tag.

Javascript in HTML Examples

Example 1 :

<html>
<head>
</head>
<body>

<script type="text/javascript" src="custom.js"></script>
</body>
</html>

Example 2 :

<html>
<head>
<script type="text/javascript" src="custom.js"></script>
</head>
<body>

</body>
</html>

JavaScript Frameworks

A Framework is basically a library of code for a certain language. Generally, the framework abstracts common tasks and makes it easier and faster for designers and developers to write their specific code. Frameworks do not really do anything by themselves, they just provide an easier platform for people to build on.

Common JavaScript Frameworks :

JavaScript File Sizes

Many JavaScript files can tend to be rather large, which can slow down the load time of your page. Popular frameworks usually offer a “minified” version of their code. You should always use this version in your pages because it will have a smaller file size.

Thanks for the reading post. I hope you like and understand the post. If you have any doubt regarding this post please comment below.

More Related Post

Leave a comment

Your email address will not be published. Required fields are marked *

0 0 0
FOLLOW ON