Link External in JavaScript for HTML with Examples
Generally we use Scripting language for developing web. In this example I explain about how to set Link External JavaScript in HTML with Simple code snippet and Examples
When we put the JavaScript Code Store in an External JavaScript File, and then File Link into your HTML Document want, then we would continue to use <script> Element, but this time we <script> follows In the src Attribute Element to Specify the URL of the JavaScript File, Link, with whom we want our Current HTML Document.
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>My javascript</title>
<script src="myjs.js"></script>
</head>
<body>
</body>
</html>
Alert("Example of link External JavaScript File.");
According to the above Code myjs.js name in our HTML Document Link to External JavaScript File and External JavaScript File as an Alert Message Specify the Code is stated above. Render we do to our Web Page, also above the JavaScript Code follows our Web Page with an Alert Dialog Box appears:
That is why, as always, Top to Bottom Render Web Page and Web Browser as a Script or get Link Element, Web Browser, and that Link has reached the Resource Web Browser Start Download in Memory of makes.
Since javascript Codes, Web Browser Executable Codes are for, so the Specified Alert Function Execute javascript Code gets Citranusar Alert Dialog Box .The thing to keep in mind that the Head Element Stylesheet Files Scripts or the Link <script> or <link> Element used to, until the Codes Web Browser Download all of them do not become Resources, the By further increasing Web Browser. As long as we have shown in the picture above do not Alert Dialog Box Click on the OK Button, and then moves forward our Web Page in Web Browser does not Render.
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title> Link External in javascript </title>
</head>
<body>
<script src="myjs.js"></script>
</body>
</html>
Since javascript is always full Web Page Load after work begins, so anytime a javascript File Web Page Link in the Head should not, but the following HTML Document Specify Just before the Closing Body Element Element using the Link should External javascript File.
External javascript File from the HTML Document Link to this way has two advantages. The first advantage is that the HTML Document is not completely Render, then Download of javascript File Web Browser does not have javascript, which is exactly the right system should have the final File, Load should be in the Web Browser.
The second advantage is that Render Web Page User is facing up. If we Scripts in the Head Element Link, then in the Download Complete Script Web Browser will not, until further Render Web Page will not. Link to the Head Element when the javascript File Web Page User may find that is big enough or the Web Site is Slow enough, so in general: User can Skip from your Site, which is not good.
Performance-wise, Yahoo, Google, Facebook, Bing, Apple etc. All the big companies like this are varied javascript Files Specify in your Web Page. Although these rules are not eternal truths and the Head or Body Script you can do anywhere in the Link. But even the always follows a Script File Just before the Closing Body Element to Specify Web Page Render is the fastest Web Browser.
External javascript File in Your HTML Document when we want to Link, then it is not necessarily that of our External javascript File Extension. Js only. Resource Extension Check the Web Browser does not ever. This is why we can Specify Script Element to a Text File, but the provision of the matter is that the External File Extension are, the Code should always be the same as javascript. Items will not matter.
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title> Link External in javascript</title>
<script src="myjs.txt"></script>
</head>
<body>
</body>
</html>
Alert("Example of link External in javascript File.");
When we have a <script> Element Specify an External Source File When Script Element between us that should not be any javascript Code Specify. We have one of the above External javascript Code File to Specify Script Code as well as the center of the Element Specify Inline javascript Code is also that which is wrong. Inline Code Specify if we do, then we do these things is as follows:
<script src="myjs.txt"></script>
<script>
Alert("Hi, It's not right way to write Inline javascript Code");
</script>
The biggest feature of javascript is that we have a way of an External Domain Image can Import into your Web Browser, the same way we also Specified JavaScript Codes on another Domain for Your Web Site Can Use And when we do so, then the External Domain Specified External javascript for Web Page Execute is the same as our way on our own Domain Specified JavaScript File is the Codes Executable.
"For example, if we are on Google's CDN Places jquery JavaScript File to'd like to use in your Web Page, we only follows the src Attribute in <script> Element of jquery JavaScript File Path of javascript that without the Associate must Place on your Web Server File-out, we all javascript File Functions Can Use for Your Web Page:
<script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.2/jquery.min.js">
</script>
Now the most important thing and that is that although we have the Use Page Level Inline javascript in the HTML Document, but we should not do. JavaScript Code Line of whether one might be, we should always an External JavaScript File Create your JavaScript Codes must type in the External File.
There are many benefits of External File.
All of a Web Page or Front Parts (HTML, CSS and javascript), etc. Individually only. The main advantage of doing this is that we can Maintain our Web Site are much better. More on our Web Site and we have ours Control Function in any of the javascript File Change or Modification of the Web Site and its effect on all Web Pages Can Apply the Internal javascript Codes us in case - a Web Page Modification will make it up to the Open.
Since the javascript File, Images and CSS File In Web Browser Cache are like, so when Open is the first of our Web Site, then all our javascript Files, User and User's Web Browser are available in the Save Web Other Pages to the Site is Open, then Open Web Pages are fast enough because the Associated javascript File Web Pages that already exist in the Web Browser. External javascript Files Use the Fast is much to our Web Site.
Inline JavaScript to use all of the Web Page Load Load in Web Browser has JavaScript Code every time is the same even if only in the JavaScript Codes. Inline JavaScript Codes in position on the Use of Web Page Speed Slow is.
A third advantage is that we need to Inline JavaScript Use the Use Symbol Encodings of various types have to Comparison Symbols Use Inline JavaScript if fitted, so we instead "<" or ">" Codes have to use. Or we have to use CDATA Element, whereas no such Restrictions External Files are not.
<noscript> Element
User Web Browser for some reason at times is JavaScript Disabled. Codes of JavaScript, which we write in this case, the Codes do not own any Effect Show Close.
This needs us normally: HTML is completed using the <noscript> Element. .Use the Web Page <noscript> Element is as follows: <html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>My javascript</title>
<script src="myjs.txt"></script>
</head>
<body>
<noscript>
<p> This Web Page requires javascript Enabled Web Browser. </p>
</noscript>
</body>
</html>
Use the <noscript> Element is always between Body Element and the Use HTML Element The Element can we have any. Between the Element Enclosed Content User can only appear in two situations:
Support to the User's Web Browser javascript does not. When the User would have been disabled javascript in the Web Browser.
In any other situation between <noscript> Element Enclosed Content User does not show up.