External JavaScript

Card image cap

JavaScript Definition

JavaScript is a client side scripting language developed by Netscape or use within HTML web pages. JavaScript is loosely based on Java and it is built into all the major modern browsers like Internet Explorer, Firefox, Chrome, Safari etc.


External JavaScript:

External JavaScript allows the reusse of same block of code on several different web pages. The JavaScript code will be written on a separate page and the web pages can make use of this code by including the page in the src attribute of the script tag.

The biggest advantage to have an external JavaScript file is that once the file has been loaded, the script will remain in the the browser's cache area. So the next time the page will be loaded from the browser's cache instead of having to reload it over the Internet. This enables faster execution.

Syntax:

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

When the browser encounters this block it will load filename.js and execute it.

Advantages of external JavaScript:

  • It separates HTML and code.
  • It makes HTML and JavaScript easier to read and maintain.
  • Cached JavaScript files can speed up page loads.

Example: External javaScript

First Let's Create a javascript file and save it with .js file.

	function popup()
	{
		alert("WelCome to aimtocode Tutorial")
	}

Now : Let's creat a HTML file then save it with .html extension and link the external javascript file(external.js that we have already created.


Result :

  WelCome to aimtocode Tutorial
Card image cap