Why loading JavaScript using "src" and CSS using "href "?

Source: Internet
Author: User

Now let me know the answers from Hax.

Theoretically, Src expresses that the content of this element will be replaced as a whole. Such as IMG, script, and IFRAME.

In HTML 2, the src attribute is extended to all elements. For example:

<Style src = "common.css">/* content is ignored */</style>

Href expresses hyperlinks. For example, element a and link.

Xhtml2 in the left-side Navigation Pane also promotes the href attribute to all elements. For example:

<Ol> <li href = "/"> homepage </LI> </OL>

Of course, xhtml2 is too powerful, so the SRC and href attributes are not generalized. However, HTML5 or later HTML will follow this design, such as the src attribute in the video/audio element.

As to why we decided to use link href for external style sheets instead of using style SRC for loading, we may think that style sheets are more in line with the characteristics of external link resources, it is closer to affiliated resources rather than embedded content. For example, to consider alternate stylesheets, you only need to link a group of style sheets at the same time, instead of loading all. Of course, you can simply refer to the legacy of history (that is, an accidental decision of a browser developer at the beginning ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.