A brief talk on lucky 28 source download File protocol and HTTP protocol and differences

Source: Internet
Author: User
Tags file transfer protocol ftp protocol

Let's look at the three-segment code:

Index.html:

Copy Code
<! DOCTYPE html>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "Width=device-width, initial-scale=1.0" >
<meta http-equiv= "x-ua-compatible" content= "Ie=edge" >
<title>Document</title>
<body>
<script src= "./index.js" async></script>
</body>
Copy Code

Index.js:

Import * as Circle from './test ';

Console.log (' Circle area: ' + Circle.area (4));
Console.log (' circumference length: ' + circle.circumference (14));

Test.js:

Copy Code
Export function Area (RADIUS = 5) {
return Math.PI radius radius;
}

Export function circumference (radius = 5) {
Return 2 math.pi radius;
}
Copy Code

Use is lucky 28 source download Dashengba.com "Holy Source Forum" enterprise-e 3266397597 module syntax, but through the examination of ideas

    1. The browser version is too low to support ES6 syntax. The browser is upgraded to the latest (Chrome), but the problem remains unresolved.

    2. module modules are not supported locally by:

$ NPM install-g Es-checker
$ es-checker

Check local support for ES6 and find the problem is not here

    1. The browser continues to report cors cross-domain issues by bable the ES6 syntax into ES5 syntax, which is not described here bable.

    2. In the external section of the answer mainly to the respondents mentioned HTTP and file, so thinking may be a protocol use error. Finally, the file is accessed via localhost local server and the error disappears.

What is the file protocol
Local File Transfer Protocol

What is file:

The file protocol is primarily used to access files on the local computer, such as opening files through Windows Explorer or by right-clicking ' open '.

How to use:

The basic format of the file protocol is as follows:

file:///file path
For example, to open the Index.txt in the TXT directory under E, enter: File:///E:/txt/index.txt in the Explorer or browser address bar. Using the file:///+ file address is actually equivalent to the address of the file. That

File:///c:/users/cli/appdata/local/temp/windowslivewriter1627300719/supfiles52f410/wangdan-se-436963[2].jpg
Equivalent to:

C:/users/cli/appdata/local/temp/windowslivewriter1627300719/supfiles52f410/wangdan-se-436963[2].jpg

What does the URI ask for a local file followed by three slashes?

The structure of the URI is:

Scheme:[//[user:[email protected]]host[:p ort]][/]path[?query][#fragment]
If there is a host, it needs to be preceded by//, so it will be written for network addresses such as HTTP or https:

It looks natural. If it is a file, the file does not have a host, so the middle of the host part is not, it becomes:

Because if there is no host, the first [] content will not exist, this kind of consent to the wording of a standard called Curie.

What is the HTTP protocol
Brief introduction:

The HTTP protocol is the abbreviation for Hyper Text Jtransfer Protocol, which is the hypertext elaboration protocol. is a transfer protocol used to transfer hypertext to a local browser from a World Wide Web server, which transmits data based on the TCP/IP communication protocol. The HTTP protocol works on the client-server architecture, where the browser sends a request to the HTTP server side as an HTTP client, and the server receives the request and sends the request to the client.

URL for http:

HTTP uses a Uniform Resource identifier URI to transfer data and establish a connection. The URL is a special type of URI.

The complete URL contains the following sections:

Protocol: The protocol portion of the URL is "https", which identifies the Web page using the HTTPS protocol, and can use multiple protocols (HTTP,HTTPS,FTP, etc.) in the Internet

Domain name: A URL can also use IP as the domain name, the URL of the domain name is www.baidu.com

Port: After the domain name, use ":" As the delimiter. If the port is omitted, the default port is used.

Virtual directory: The virtual directory is not a required part. is the first "/" from the beginning of the domain name to the last "/".

File name: From the Last "/" after the domain name to "?" "So far, is the file name part, if there is no"? ", then from the domain name after the last"/"Start to" # "so far, is the document part, if not"? "and" # ", then from the last"/"after the domain name to the end, is the file name section. The file name section is also not a required part of the URL, and if omitted, the default file name is used.

Anchor: From the beginning of "#" to the end are anchors, anchors are not a necessary part of the URL.

Parameters: from "? "Start to" # "so far as the middle parameter, the argument can be allowed to have more than one parameter, the middle with" & "as the delimiter.

Request Method:

Copy Code
The GET request specifies the page information and returns the entity principal.
HEAD is similar to a GET request, except that there is no specific content in the returned response to get the header
POST submits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is included in the request body. A POST request may result in the creation of new resources and/or modification of existing resources.
PUT replaces the contents of the specified document with the data that the client transmits to the server.
The delete request server deletes the specified page.
The Connect http/1.1 protocol is reserved for proxy servers that can change connections to pipelines.
The OPTIONS allows clients to view server performance.
TRACE echoes the requests received by the server, primarily for testing or diagnostics.
Copy Code

Browser through
The file protocol is used to access files on the local computer, like opening a file through a resource manager, where the main requirement is that it is local, that is, the file protocol is a source of files that accesses your native machine.

HTTP access to the local HTML file, equivalent to the native as an HTTP server, and then through localhost access to your own computer on the local server, and then through the HTTP server to access your native file resources.

The simple point is that file simply requests a local file and opens it as an unresolved static file for the server. And HTTP is to build a local server and then through the server to dynamically parse to get the file.

Other differences:

The file protocol can only be accessed locally

Local HTTP server open port can also be accessed by others to the files on your computer, but the file protocol does not

The file protocol should have an HTTP-like remote access, which is the FTP protocol, which is the document transfer Protocol.

File protocol cannot implement cross-domain

Problem solving
Start accessing index.html directly through the file protocol, introducing index.js statically in index.html and importing test.js in Index.js. The import process requires an HTTP server to parse the ES6 syntax and add header information to the cross-domain introduction of test.js, but the file protocol is equivalent to static access through the resource Manager index.html, the intermediate process does not participate in the HTTP server parsing, so the ES6 import is not recognized Grammar.

A brief talk on lucky 28 source download File protocol and HTTP protocol and differences

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.