Home Web Front-end JS Tutorial Detailed explanation on the use of url, href and src

Detailed explanation on the use of url, href and src

Jun 14, 2018 am 11:43 AM
href src url

This time I will bring you a detailed explanation of the use of url, href, and src, and what are the precautions for the use of url, href, and src. The following is a practical case, let's take a look.

1. The concept of URL

Uniform Resource Locator (or Uniform Resource Locator/location address, URL address, etc., English: Uniform Resource Locator, often abbreviated as URL), sometimes also commonly known as web address (web address). Just like a house number on the Internet, it is the address of a standard resource on the Internet.

2. URL format

2.1 Standard format

Protocol type:[// Server address[:port number]][/resource level UNIX file path]File name? Query

2.2 Full format

Protocol type:[//[Access resources Required credential information@]server address[:port number]][/resource level UNIX file path]file name?query
where [access credential information@;:port number;?query;#fragment ID] are all options Fill in the items.

3. URL syntax rules

For example, the URL http://segmentfault.com/html/index.asp must comply with the following Syntax rules:

scheme: //host.domain:port/path/filename

3.1 Description

(1) scheme - Define Internet services type. The most common type is http

(2) host - defines the domain host (the default host for http is www)

(3) domain - defines the Internet domain name, such as w3school.com.cn

(4):port - defines the port number on the host (the default port number for http is 80)

(5) path - defines the path on the server (if omitted, the document must be located in the root directory of the website).

(6)filename - defines the name of the document/resource

3.2 URL Schemes

The following are some of the most popular schemes:

Scheme Access for...
http Hypertext Transfer Protocol Ordinary web pages starting with http://. No encryption.
https Secure Hypertext Transfer Protocol Secure web page. Encrypt all information exchanged.
ftp File Transfer Protocol is used to download or upload files to a website.
file
A file on your computer.

4. Types of URL

4.1 Absolute URL

Absolute URL (absolute URL) displays the file Full path, meaning that the location of the absolute URL itself has nothing to do with the location of the actual file being referenced.

4.2 Relative URL

A relative URL uses the location of the folder containing the URL itself as a reference point to describe the location of the target folder.

In general, you should always use relative URLs for files on the same server, they are easier to type and more convenient when moving pages from the local system to the server, as long as each file is relative The position remains unchanged and the link is still valid.

The following are several special symbols used to establish paths and their meanings.

(1) .: Represents the current directory, relative path. For example: Text or

(2) ..: represents the upper directory, relative path. For example: text or

(3) ../../: represents the upper-level directory The upper directory, relative path. For example:

(4) /: represents the root directory, absolute path. For example: [text] (/abc) or

5. The concept of href

5.1 Specification Explanation

href (Hypertext Reference) specifies the location of a network resource, thereby defining a link between the current element or current document and the required anchor or resource defined by the current attribute. Link or relationship.

5.2 Popular understanding

The purpose of href is not to reference resources, but to establish a connection so that the current tag can be linked to the target address.

6. The concept of src

source (abbreviation) points to the location of an external resource. The pointed content will be applied to the current document. The location of the label.

7. The difference between href and src

7.1 Different resource types requested

(1 ) href points to the location of the network resource and establishes a connection with the current element (anchor) or current document (link).

(2) When requesting the src resource, the resource it points to will be downloaded and applied to the document, such as JavaScript scripts, img images;

7.2 The results are different

(1) href is used to establish a connection between the current document and the referenced resource;

(2) src is used to replace the current content;

7.3 Browse The browser parsing methods are different

(1) If added to the document, the browser will recognize the document as a CSS file, download the resource in parallel and will not stop processing the current document. This is why it is recommended to use the link method to load CSS instead of using the @import method.

(2) When the browser parses it, it will suspend the downloading and processing of other resources until the resource is loaded, compiled, and executed. The same is true for pictures and frames, which is similar to applying the pointed resource to Current content. This is why it is recommended to place js scripts at the bottom instead of the head.

8. The difference between link and @import

Both are ways of externally referencing CSS, but there are certain differences:

(1) link is an XHTML tag. In addition to loading CSS, it can also define other transactions such as RSS; while @import belongs to the CSS category and can only load CSS.

(2) When link refers to CSS, it is loaded at the same time when the page is loaded; @import requires the page to be fully loaded before loading.

(3) link is an XHTML tag and has no compatibility issues; @import was proposed in CSS2.1 and is not supported by lower version browsers.

(4) link supports using Javascript to control the DOM to change the style; while @import does not support it.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to use Node.js to register email activation

jQuery makes images scroll and fade in and out

The above is the detailed content of Detailed explanation on the use of url, href and src. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP function introduction—get_headers(): Get the response header information of the URL PHP function introduction—get_headers(): Get the response header information of the URL Jul 25, 2023 am 09:05 AM

PHP function introduction—get_headers(): Overview of obtaining the response header information of the URL: In PHP development, we often need to obtain the response header information of the web page or remote resource. The PHP function get_headers() can easily obtain the response header information of the target URL and return it in the form of an array. This article will introduce the usage of get_headers() function and provide some related code examples. Usage of get_headers() function: get_header

Why NameResolutionError(self.host, self, e) from e and how to solve it Why NameResolutionError(self.host, self, e) from e and how to solve it Mar 01, 2024 pm 01:20 PM

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

What do src and href mean? What do src and href mean? Aug 16, 2023 pm 05:00 PM

src and href are respectively, 1. src is the abbreviation of source, which is used to specify the path of external resources. It is usually used to embed external files, such as pictures, audios, videos, etc. The src attribute is generally used on img, script, iframe and other tags. ; 2. href is the abbreviation of hypertext reference, which is used to specify the path of the target resource of the hyperlink. It is usually used to link to external documents or other pages. The href attribute is generally used on tags such as a and link.

What is the difference between html and url What is the difference between html and url Mar 06, 2024 pm 03:06 PM

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

How to get your Steam ID in a few steps? How to get your Steam ID in a few steps? May 08, 2023 pm 11:43 PM

Nowadays, many Windows users who love games have entered the Steam client and can search, download and play any good games. However, many users' profiles may have the exact same name, making it difficult to find a profile or even link a Steam profile to other third-party accounts or join Steam forums to share content. The profile is assigned a unique 17-digit id, which remains the same and cannot be changed by the user at any time, whereas the username or custom URL can. Regardless, some users don't know their Steamid, and it's important to know this. If you don't know how to find your account's Steamid, don't panic. In this article

How to use URL encoding and decoding in Java How to use URL encoding and decoding in Java May 08, 2023 pm 05:46 PM

Use url to encode and decode the class java.net.URLDecoder.decode(url, decoding format) decoder.decoding method for encoding and decoding. Convert into an ordinary string, URLEncoder.decode(url, encoding format) turns the ordinary string into a string in the specified format packagecom.zixue.springbootmybatis.test;importjava.io.UnsupportedEncodingException;importjava.net.URLDecoder;importjava.net. URLEncoder

Scrapy optimization tips: How to reduce crawling of duplicate URLs and improve efficiency Scrapy optimization tips: How to reduce crawling of duplicate URLs and improve efficiency Jun 22, 2023 pm 01:57 PM

Scrapy is a powerful Python crawler framework that can be used to obtain large amounts of data from the Internet. However, when developing Scrapy, we often encounter the problem of crawling duplicate URLs, which wastes a lot of time and resources and affects efficiency. This article will introduce some Scrapy optimization techniques to reduce the crawling of duplicate URLs and improve the efficiency of Scrapy crawlers. 1. Use the start_urls and allowed_domains attributes in the Scrapy crawler to

How to add URL prefix to SpringBoot multiple controllers How to add URL prefix to SpringBoot multiple controllers May 12, 2023 pm 06:37 PM

Preface In some cases, the prefixes in the service controller are consistent. For example, the prefix of all URLs is /context-path/api/v1, and a unified prefix needs to be added to some URLs. The conceivable solution is to modify the context-path of the service and add api/v1 to the context-path. Modifying the global prefix can solve the above problem, but there are disadvantages. If the URL has multiple prefixes, for example, some URLs require prefixes. If it is api/v2, it cannot be distinguished. If you do not want to add api/v1 to some static resources in the service, it cannot be distinguished. The following uses custom annotations to uniformly add certain URL prefixes. one,

See all articles