What is the difference between the following two codes in an HTML file? If I add one more javascript file xyz.js
after including the abc.js
, is there any priority associated when the scripts are being used?
First code:
<script src="js/abc.js" type="text/javascript" language="javascript"> </script>
Second code:
<script language="javascript">
/*same code of abc.js*/
</script
TypeScript is an object-oriented programming language developed by Microsoft Corporation, whereas JavaScript is the programming language for the web. TypeScript is an open-source language to build large-scale web apps, whereas JavaScript is a server-side programming language that helps to develop interactive web pages.
In order to use JavaScript on an HTML web page, you must use the <script> tag to either write your JavaScript code directly in your HTML markup or to link to an external JavaScript file. This guide shows you how to use the <script> tag to link JavaScript to an HTML page.
Placing scripts in external files has some advantages: It separates HTML and code. It makes HTML and JavaScript easier to read and maintain. Cached JavaScript files can speed up page loads.
The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
The primary difference is that the javascript file can be cached by the browser and network devices so the user doesn't have to download it on every page load.
So if you have 100k of javascript files, your visitor only needs to download them once. Otherwise, they'd have to download those same exact 100k every page load and visit.
This allow applies to inline and external CSS and images as well!!
Granted this is only the tip of the iceburg of caching and browser performance (Steve's book is one of the web 'bibles'):
http://yuiblog.com/blog/2006/11/28/performance-research-part-1/
http://www.yuiblog.com/blog/2007/01/04/performance-research-part-2/
http://www.stevesouders.com/
What is the difference between the following two codes in an HTML file?
One requires an extra HTTP request, but gets cached. The other doesn't.
If I add one more javascript file xyz.js after including the abc.js, is there any priority associated when the scripts are being used?
Loading of external scripts is blocking. The first one will be loaded first. Then the second one will be loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With