What are Advantages of Using External Javascript ?

Placing JavaScript code in external js files has few advantages over inline scripts...

Segregating HTML and JavaScript code helps to manage the code base better.

To improve development output designers can work along with coders in parallel without code conflicts.

This approach also works well with modern source code version control systems like GIT and SVN.

Segregating HTML and JavaScript makes code as well as HTML is easily readable.

Segregated external JavaScript files are cached by browsers and can speed up page load times.

These small js files can be minified to reduce the size and make it not readable by humans, using Google closure or YUI Compressor or other.

Many popular JavaScript libraries are available as hosted on content delivery networks (cdn) and you can simply point to them using the URL in the src, this avoids copying the js file to local folder.

Using external Js you can take benifits of advanced tools such as RequireJS or CommonJS to load these scripts logically and modularly.



You May Interest

What are Asynchronous Scripts in Javascript ?

JavaScript Making Lowercase

What are Deferred Scripts in Javascript ?

What are Control Flow Statements in Javascript ?

What is this Keyword in Javascript ?