Difference between src and href attributes

Difference between src and href attributes

There is a difference between src and href, and they can be confused. src is used to replace the current element, and href is used to establish a connection between the current document and the referenced resource.

src is the abbreviation of source, which points to the location of external resources. The content pointed to will be embedded in the location of the current tag in the document. When the src resource is requested, the resource it points to will be downloaded and applied to the document, such as js scripts, img images, frame elements, etc.

<script src ="js.js"></script>

When the browser parses this element, it will pause the downloading and processing of other resources until the resource is loaded, compiled, and executed. The same applies to elements such as images and frames, which is similar to embedding the pointed resource into the current tag. This is also why you should put js scripts at the bottom instead of at the top.

href is the abbreviation of Hypertext Reference, which points to the location of a network resource and establishes a link with the current element (anchor) or the current document (link). If we add

<link href="common.css" rel="stylesheet"/>

Then the browser will recognize the document as a CSS file, and will download the resources in parallel without stopping the processing of the current document. This is why it is recommended to use the link method to load CSS instead of the @import method.

<<:  Mysql example of splitting into multiple rows and columns by specific symbols

>>:  Looping methods and various traversal methods in js

Recommend

Detailed explanation of CSS float property

1. What is floating? Floating, as the name sugges...

Vue implements bottom query function

This article example shares the specific code of ...

How to connect to MySQL database using Node-Red

To connect Node-red to the database (mysql), you ...

JavaScript implements page scrolling animation

Table of contents Create a layout Add CSS styles ...

Introduction and tips for using the interactive visualization JS library gojs

Table of contents 1. Introduction to gojs 2. Gojs...

How to add a disk in Vmware: Expand the disk

This article describes how to add or expand a dis...

JS practical object-oriented snake game example

Table of contents think 1. Greedy Snake Effect Pi...

Solve the problem that the docker container cannot ping the external network

Today, when I was building a redis environment in...

Vue3 encapsulates its own paging component

This article example shares the specific code of ...

Four ways to modify the default CSS style of element-ui components in Vue

Table of contents Preface 1. Use global unified o...

React Native JSI implements sample code for RN and native communication

Table of contents What is JSI What is different a...

Detailed explanation of browser negotiation cache process based on nginx

This article mainly introduces the detailed proce...

Experience of redesigning the homepage of TOM.COM

<br />Without any warning, I saw news on cnB...

MySQL implements a solution similar to Oracle sequence

MySQL implements Oracle-like sequences Oracle gen...

Detailed explanation of the difference between chown and chmod commands in Linux

In Linux system, both chmod and chown commands ca...