URL(Uniform Resource Locator)

Uniform Resource Locator (URL) is a concise representation of the location and access method of resources available on the Internet. It is the address of standard resources on the Internet. Every file on the Internet has a unique URL that contains information indicating where the file is and what the browser should do with it.

structure

The basic URL contains the mode (or protocol), server name (or IP address), path, and file name, such as protocol :// authorization/path? The query “. The complete common UNIFORM Resource Identifier syntax, with the authorization part, looks like this: Protocol :// Username: password @subdomain name. Top-level domain name: port number/directory/file name. File suffix? Parameter = value # flag

Part I:

Mode/Protocol (Scheme) : This tells the browser how to handle the file that will be opened. The most common mode is Hypertext Transfer Protocol, or HTTP, which is used to access networks. 1 Other agreements are as follows:

  • HTTP – Hypertext Transfer Protocol resource
  • HTTPS – Hypertext transfer protocol over secure Sockets Layer
  • FTP — File transfer protocol
  • Mailto — Email address
  • Ldap – Lightweight directory Access Protocol search
  • File – A file shared on a local computer or online
  • News – Usenet newsgroups
  • Gopher, gopher protocol
  • Telnet – Telnet protocol

Part II:

The name or IP address of the server where the file resides, followed by the path to the file and the name of the file itself. The name or IP address of the server is sometimes followed by a colon and a port number. It can also contain the user name and password necessary to access the server. The path section contains the path definition of a hierarchical structure, generally separated by a slash (/). The query section is typically used to pass parameters needed to make dynamic queries to the database on the server.

classification

1. Absolute URLS

Absolute urls display the complete path to the file, which means that the location of the absolute URL itself is independent of the location of the actual file being referenced.

2. Relative urls

Relative urls Describe the location of the target folder using the location of the folder containing the URL itself as a reference point. (that is, if the target file to the current page contains the URL of the page) in the same directory, then the relative URL of this file is only the file name and extension, if the target files in the current directory subdirectory, then its relative URL is the subdirectory name, followed by a slash, then the target file filename and extension.

If you want to reference a file in a directory higher up in the file hierarchy, use two periods and a single slash. Can be combined and reuse of two periods and a slash, and references to any of the files in the current file on your hard disk, in general, for the same file on the server, you should always use a relative URL, they are more easy to input, and in the page from the local system to the server, more convenient, as long as the relative position of each file remains the same, The link is still valid.

Here are some special symbols used to establish paths and what they mean.

  • .: indicates the relative path of the current directory. Such as:<a href="./abc">The text</a><img src="./abc" />
  • .: indicates the relative path of the directory at the previous layer. Such as:<a href=".. /abc">The text</a><img src=".. /abc" />
  • . /.. /: indicates the relative path of the directory at the previous layer. Such as:<img src=".. /.. /abc" />
  • /: indicates the root directory and the absolute path. Such as:<a href="/ ABC "><img src="/abc" />
  • D:/abc/: indicates the root directory and the absolute path.

When using relative paths, we use the symbol “. To represent the current directory, using the symbol “..” Represents the parent directory of the current directory.

Key: the definition and difference between href and SRC

Href and SRC are distinct and not interchangeable. We use SRC on replaceable elements, whereas href is used to establish a relationship between the involved document and external resources.

Href (Hypertext Reference) specifies the location of a network resource to define a link or relationship between the current element or document and the desired anchor or resource defined by the current attribute. When we write:

<link href="style.css" rel="stylesheet" />
Copy the code

The browser understands that the current resource is a style sheet and that page parsing is not paused (rendering may be paused because the browser needs style rules to draw or render the page). This is not the same as writing CSS file contents in

The SRC (Source) attribute merely empowers the current resource to the location defined by the current document element. When the browser finds

<script src="script.js"></script>
Copy the code

Page loading and processing is paused before the browser downloads, compiles, and executes the file. This process is similar to putting js files into

Reference:

  • Stackoverflow.com/questions/3…
  • Reference.sitepoint.com/css/replace…
  • Google