Saturday 23 November 2013

Javascript - Inline Code VS External Files

Leave a Comment

Inline Code

<html>
<head> 
<script type="text/javascript">
function a()
{
alert('hello world'); 
} 
</script>
</head>
<body>
:
:
</body>
</html>

External Files

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

scriptone.js

function a()
{
alert('hello world'); 
} 

As you can see from the above example,  what is the advantage to put all script in one file and just call it from html(External Code) instead of just write it in html(inline code).?

The answer is here :

  1.  By using external code, the javascript code is much more maintainability :- javascript Code that is sprinkled throughout various HTML pages turns code maintenance into a problem. It is much easier to have a directory for all javascript files so that developers can edit JavaScript code independent of the markup in which it is used.
  2. Caching - browser cache all externally linked JavaScript files according to specific settings, meaning that if two pages are using the same file, the file is download only once. This ultimately means faster page load times.
  3. Future-proof - By including JavaScript using external files, there is no need use the XHTML. The syntax to include external files is the same for both HTML and XHTML.


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.