A preface.

The purpose of this article is to record the more important knowledge points in the process of reading, for their later reference, especially to share with you

2. The body of

1. The JavaScript in HTML

1.1 < script > element

The <script> element has the following seven attributes:

  • Async: Optional. Indicates that you should start downloading the script immediately, but you cannot prevent other page actions, such as downloading resources or waiting for other scripts to load. This applies only to external script files.

  • Charset: Optional. The code character set specified with the SRC attribute. This property is rarely used because most browsers don’t care about its value.

  • Crossorigin: Optional. Configure CORS (Cross-source resource sharing) Settings for related requests. CORS is not used by default. Crossorigin = “anonymous” profile requests do not have to set credential flags. Crossorigin =”use-credentials” sets the credential flag, which means that outbound requests contain credentials.

  • Defer: Optional. Indicates that the script can be deferred until the document is fully parsed and displayed. This applies only to external script files. In IE7 and earlier, you can specify this property for inline scripts as well.

  • Integrity: optional. Allows the docking of received resources with the specified cryptographic signature to verify Subresource Integrity (SRI). If the signature of the received resource does not match the signature specified by this property, an error is reported and the script is not executed. This property can be used to ensure that a Content Delivery Network (CDN) does not serve malicious Content.

  • SRC: Optional. Represents an external file that contains the code to execute.

  • Type: Optional. Instead of language, represents the content type (also known as MIME type) of the scripting language in the code block. By convention, this value is always “text/javascript”, although “text/javascript” and “text/ecmascript” are obsolete. The MIME type of a JavaScript file is usually “application/ X-javascript “, but giving this value to the type attribute can cause the script to be ignored. Other values that work in non-IE browsers are “application/javascript” and “application/ecmascript”. If the value is module, the code is treated as an ES6 module, and only then can the import and export keywords appear in the code.

The way the browser parses the inline script determines that when it sees a string, it will treat it as a closing tag. To avoid this problem, just escape the character “\” :

<script> 
 function sayScript() { 
 	console.log("<\/script>"); 
 } 
</script>
Copy the code

1.2 summary

  • To include an external JavaScript file, you must set the SRC property to the URL of the file to include. Files can be on the same server as web pages, or they can be in completely different domains.
  • All <script> elements are interpreted in the order in which they appear on the page. Without usingdeferasyncProperty, the code contained in <script> elements must be interpreted in strict order.
  • For scripts that do not delay execution, the browser must finish interpreting the code in the