Yes. There is a difference between src and href and they cannot be used interchangeably. We use src for replaced elements while href to establish relationship between referenced document and external resource.
The href (hypertext reference) attribute specifies the location of a web resource and thus a link or relationship between the current element (in the case of anchors) or the current document (in the case of links) and the destination anchor or resource defined by this attribute. defines.
When we write:
<link href='style.css' rel='stylesheet' />
The browser understands that this resource is a stylesheet and that the processing of the page has not stopped parsing (rendering may be stopped because the browser needs style rules to paint and render the page). This is not the same as dumping the content of a CSS file inside a style tag. (It is therefore advisable to use links instead of @import to attach stylesheets to your HTML document.)
The src(source) attribute embeds the file into the contemporary webpage.
For example : when the browser finds
<script src='script.js'></script>
So, when the web page gets the src attribute it gets some additional documents from some other source in the server. It blocks the loading and processing of a contemporary webpage until it has loaded or fetched the entire file and is compiled or executed in the current document. JS files inside script tags serve to dump content into websites. The image tag is also the same, it is an empty tag and the content, which should come inside it, is defined by the src attribute. Therefore, the browser blocks the loading of the document or webpage until the image is completely rendered.
This is the reason why it is advisable to load all JavaScript files at the bottom (after the </body> tag)
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Yes. There is a difference between src and href and they cannot be used interchangeably. We use src for replaced elements while href to establish relationship between referenced document and external resource.
The href (hypertext reference) attribute specifies the location of a web resource and thus a link or relationship between the current element (in the case of anchors) or the current document (in the case of links) and the destination anchor or resource defined by this attribute. defines.
When we write:
The browser understands that this resource is a stylesheet and that the processing of the page has not stopped parsing (rendering may be stopped because the browser needs style rules to paint and render the page). This is not the same as dumping the content of a CSS file inside a style tag. (It is therefore advisable to use links instead of @import to attach stylesheets to your HTML document.)
The src(source) attribute embeds the file into the contemporary webpage.
For example : when the browser finds
So, when the web page gets the src attribute it gets some additional documents from some other source in the server. It blocks the loading and processing of a contemporary webpage until it has loaded or fetched the entire file and is compiled or executed in the current document. JS files inside script tags serve to dump content into websites. The image tag is also the same, it is an empty tag and the content, which should come inside it, is defined by the src attribute. Therefore, the browser blocks the loading of the document or webpage until the image is completely rendered.
This is the reason why it is advisable to load all JavaScript files at the bottom (after the </body> tag)