I've tried using both the following source-reference-lines. They both compile. But what is the difference?
1st method:
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
2nd method:
<link href="~/Scripts/jquery-1.4.1.js" type="text/javascript" />
Note: There's also the similar Difference between script
and link as="script"
tags which asks about <link href="js/script.js" as="script">
, which is different.
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.
JavaScript became the default language for HTML5 and modern browsers. Therefore, now adding text/javascript isn't required in <script> tag.
The best practice is to put JavaScript <script> tags just before the closing </body> tag rather than in the <head> section of your HTML. The reason for this is that HTML loads from top to bottom. The head loads first, then the body, and then everything inside the body.
To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.
link
tag is used to relate stylesheets or any other linked documents instead of including javascript files.
The HTML Link Element <link>
specifies relationships between the current document and other documents. Possible uses for this element include defining a relational framework for navigation and linking the document to a style sheet.
rel
Attribute:
This attribute names a relationship of the linked document to the current document. The attribute must be a space-separated list of the link types values. The most common use of this attribute is to specify a link to an external style sheet: the rel attribute is set to stylesheet, and the href attribute is set to the URL of an external style sheet to format the page. WebTV also supports the use of the value next for rel to preload the next page in a document series.
Possible Values:
alternate - An alternate version of the document (i.e. print page, translated or mirror)
stylesheet - An external style sheet for the document
start - The first document in a selection
next - The next document in a selection
prev - The previous document in a selection
contents - A table of contents for the document
index - An index for the document
glossary - A glossary (explanation) of words used in the document
copyright - A document containing copyright information
chapter - A chapter of the document
section - A section of the document
subsection - A subsection of the document
appendix An appendix for the document
help A help document
bookmark A related document
shortcut icon A related (favorite icon) image of the document
While The HTML Script Element <script>
is used to embed or reference an executable script within an HTML or XHTML document.
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