Read "JavaScript DOM Programming Art (2nd edition)" Note 5

Source: Internet
Author: User

I read the fifth chapter today and talked about a lot of things I've never thought about: smooth degradation, separation of javascript, backwards compatibility, performance considerations. The reasons for these problems are: some browsers do not support JS script, or some browsers can support JS script, but the user turned off the JS interpretation function, or some browsers can only support some JS script. Without this in mind, people who visit our website may encounter a variety of problems and therefore no longer visit our website.

Smooth degradation: Ensure that Web pages work correctly without JavaScript

If JavaScript scripts are used correctly, it allows visitors to navigate our site smoothly without their browsers supporting JavaScript, which is known as a smooth degradation, that is, although some features are not available, the most basic operations can still be completed successfully.

Progressive enhancement: Use some additional information layers to wrap the raw data. Web pages created in accordance with the "progressive enhancement" principle almost all conform to the "smooth degradation" principle

Separating javascript: Separating the structure and content of a Web page from the action behavior of a JavaScript script

Window.onload =function() {  if(!document.getelementsbytagname)return false; varLnks = document.getElementsByTagName ("a");  for(vari=0; i<lnks.length; i++) {    if(Lnks[i].getattribute ("class") = = "Popup") {Lnks[i].onclick=function() {popUp ( This. getattribute ("href")); return false; }    }  }}functionpopUp (Winurl) {window.open (Winurl,"Popup", "width=320,height=480");}

Backwards compatibility: Make sure older browsers don't die because of your JavaScript scripts

Object detection: Whenever a method is packaged in an if statement, it is possible to determine what action should be taken based on whether the evaluation result of the conditional expression of the IF statement is true (the method exists) or False (this method does not exist).

When using object detection, be sure to delete the parentheses after the method name, and if you do not delete it, the test will be the result of the method, regardless of whether the method exists.

function myFunction () {  if(document.getElementById) {    statements using getElementById  }} 

Although it is a simple if statement, it ensures that the "old" browsers do not cause problems with my scripting code, so that the script has good backwards compatibility.

Browser sniffing technology: addresses backward compatibility issues by extracting information from a browser vendor.

Performance considerations: Determining the optimal performance of script execution

1. Minimize access to the DOM and minimize markup

2. Merging and placing scripts

Reducing the number of requests is usually the first thing to consider when performance optimizations are in place.

The location of the script in the markup also has a significant impact on the initial load time of the page, which, according to the HTTP specification, can only download up to two files at a time from the same domain name. While downloading the script, the browser will not download any other files, even the files from different domain names will not be downloaded, all other resources must wait until the script is loaded to download

3. Compression scripts

please look this article

I have to say, I used to write Web files, never consider the problem of high performance, read the book after the benefit Ah! Later I will pay attention to this aspect of the problem, make their website more perfect, more perfect!

Read "JavaScript DOM Programming Art (2nd edition)" Note 5

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.