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 Javascript Echarts air quality map effect

We need to first combine the air quality data wit...

Nginx load balancing algorithm and failover analysis

Overview Nginx load balancing provides upstream s...

Teach you how to make cool barcode effects

statement : This article teaches you how to imple...

MySQL index principle and query optimization detailed explanation

Table of contents 1. Introduction 1. What is an i...

Vue implements multiple selections in the bottom pop-up window

This article example shares the specific code of ...

How to create components in React

Table of contents Preface Component Introduction ...

How to keep running after exiting Docker container

Phenomenon: Run an image, for example, ubuntu14.0...

Teach you MySQL query optimization analysis tutorial step by step

Preface MySQL is a relational database with stron...

Detailed tutorial on compiling and installing python3.6 on linux

1. First go to the official website https://www.p...

CentOS6 upgrade glibc operation steps

Table of contents background Compile glibc 2.14 M...

Simple steps to encapsulate components in Vue projects

Table of contents Preface How to encapsulate a To...

Common styles of CSS animation effects animation

animation Define an animation: /*Set a keyframe t...

Use Xshell to connect to the Linux virtual machine on VMware (graphic steps)

Preface: I recently started to study the construc...