JavaScript Libraries--jquery and Zepto
jquery is a widely used JavaScript library on the web, it provides a lot of tools and API functions, the people who use it are quite common, and the threshold used is lower. Its API semantics are very tolerant to beginners, and there are various mistakes that do not throw JavaScript errors. Most jquery methods are linked, meaning that these methods all return jquery objects, so you can link any number of methods to a DOM reference. Because of this, there are a lot of people who contribute code to jquery, which leads to a cost for every function of jquery, a growing code base, and a maximum burden on file size. jQuery2.0 at this point, directly choose to abandon IE6, IE7, IE8, These codes account for a large part of the jQuery1.9, but don't worry, jQuery2.0 and 1.9 are compatible, which means that all 2.0 unsupported browsers can have conditional comments loaded jQuery1.9.
<!-[if it IE 9]>
<script src= "Jquery-1.9.x.js" ></script>
<! [endif]-->
<--[if GTE IE 9]><!-->
<script src= "Jquery-2.x.x.js" ></script>
<!--<! [endif]-->
The popularity of jquery is also a great place to be proud of, since so many sites are using it, each site is not very meaningful to introduce it, it is not necessary to use the user every visit to a jquery site to download the same jquery core file. So Google deployed jquery on the CDN (content delivery site), which saved the download time for users by improving the way jquery was introduced to the site. Although there are still a lot of sites still put jquery on their own site, but have done enough to use the site Goole CDN. If a user visits this site for the first time, there is no need to download jquery. This approach is beneficial for improved performance, which means that the more websites you do, the greater the benefits of this approach. Goole's CDN is especially easy to use, just to point the script source to the Goole server.
<script src= "//ajax.gooleapis.com/ajax/libs/jquery/1/jquery.min.js" ><script>
The above script is requesting the latest stable version of jquery to introduce the site, but generally do not do this because the API in jquery is discarded, especially from 1.9 to 2.0, so it is best to indicate the desired version.
<script src= "//ajax.gooleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ><script>
This code indicates in the path the 1.9.1 version of jquery. The HTTP protocol that is ignored here is to ensure that the browser can use the protocol that the page uses, which avoids the browser complaining that the requested resource Protocol does not match. However, if you open the local HTML file using the FILE:///protocol, it will not work.
Originally a library developed for mobile, Zepto is a lightweight alternative to jquery because its APIs are similar to jquery, and the files are smaller, which is a good choice for any project. Zepto The biggest advantage is its file size, only 8k more, is the smallest of the currently fully functional library, although not small, Zepto provides the tools sufficient to meet the needs of the development process. Most of the common APIs and methods used in jquery are Zepto, and there are some APIs and methods in Zepto that are not available in jquery and are easily made with some custom JavaScript. In addition, because the Zepto API is mostly compatible with jquery, it is extremely easy to use, and if you are familiar with jquery, you can easily master Zepto. You can reuse many of the methods in jquery in the same way, or you could string together a method to get more concise code, even without looking at its documentation.
For the mobile program, Zepto also has some basic touch events can be used to do touch screen interaction, such as: Tap Event--tap,singletap,doubletap,longtap;
Swipe event--swipe,swipeleft,swiperight,swipeup,swipedown.
But one thing, Zepto is not support IE browser, this is not Zepto developers Thomas fucks on cross-browser issues, but after careful consideration to reduce the size of the file, the decision to make, Just like the jquery team in version 2.0 no longer supports the same old version of IE.
For a long time, the compatibility of IE has made countless developers suffer. It just doesn't follow the standard, and every big version has its own quirks. IE has made great efforts in newer versions to address these compatibility issues. But in fact, IE still uses its own nonstandard way to deal with some JavaScript and DOM problems, and with the advent of HTML5 standards and features, it has been left behind by other major browsers.
Most JavaScript libraries, such as jquery, are using extra code to solve cross-browser problems, but the amount of code written to solve this problem is considerable. Zepto gave up the problem in order to lose weight. This is good for mobile programs, because in mobile terminals generally do not have to worry about encountering ie. But this is a deadly problem for desktop applications.
Because Zepto uses jquery syntax, it suggests that jquery be used as a fallback on IE in the documentation. That way, the program can still be in IE, while other browsers can enjoy the advantages of Zepto in file size, but their two API is not fully compatible, so use this method must be careful, and to do adequate testing.
Of course, you can not use JavaScript libraries at all. Even a small JavaScript library, such as zepto, can cause programs to swell up unnecessarily. The biggest benefit of writing your own javascript is that you only need to write and introduce what you need, and the biggest drawback is that it takes longer to develop. By definition, the JavaScript library contains many of the features commonly used in programs, but it is not possible for each program to use all of its functions. Those extra, less-than-used JavaScript are unnecessary lumps. However, you have to choose between file size and development time, and if you have never written a JavaScript program from the beginning, you may underestimate the development time required for the entire program. Believe that even if you know you have to write a lot of scripts to implement all the functions your program needs, you may not consider the amount of work you need to support multiple browsers.
Compared to cross-browser JS, the cross-browser problem of CSS is simply trivial. The early browser wars have left a variety of bizarre problems that are becoming increasingly apparent, forcing you to do different implementations for different browsers, and these are slightly different ways of handling them. A common example is the cross-browser time processor, such as the OnClick event. All modern browsers support mouse events with Addevenlistener bindings.
Var Bt=document.getelementbyid ("BT");
Bt.addeventlistener ("click", Function (e) {
Alert ("This is a alert");
})
The event binding function under IE is attachevent, which supports a full range of IE, but if you use this function to bind events in other kernel browsers such as Chrome, the browser will make an error.
Var Bt=document.getelementbyid ("BT");
Bt.attachevent ("onclick", function (e) {
Alert ("This is a alert");
})
Therefore, there is no absolute advantage in development, the appropriate choice of JavaScript library, or the use of native JS are based on their own development needs to weigh.
Compare jquery and Zepto