9 Myths about using jquery

Source: Internet
Author: User

Do not forget to use the latest version oh, after all, each version of the update will certainly improve in terms of functionality or performance, or fix a few bugs, but sometimes lazy people do not want to study the new version of the changes, so remind you not to forget the new project with the new must be better than the old version.

AD:

jquery is so easy to use that we sometimes forget the existence of CSS. When we use CSS, we almost don't think about performance, because it's already so fast that it's not worth the effort to do any optimizations. But in the real world, jquery can lead to performance problems that make developers crazy. Sometimes you lose a few milliseconds without perceiving it. We also easily forget some of the features and continue to use some of the old (and not so good) features. Here are 9 mistakes you can make with the jquery process, and see if you've ever met one before.

1. Do not use the latest version

Do you see if your machine is up to date? Perhaps you do not have a good site to update one, after all, this workload may not pay you, but the new development projects? Do not forget to use the latest version oh, after all, each version of the update will certainly improve in terms of functionality or performance, or fix a few bugs, but sometimes lazy people do not want to study the new version of the changes, so remind you not to forget the new project with the new must be better than the old version.

2. jquery without the use of cdn-hosted

Many people like to download on their servers and then call. It seems that the subconscious files in their own hands are more secure. But most of the time, unless you're particularly bullish, your server is less than the CDN server. If the traffic is small, there may be no impact, but if the traffic once large, the performance of the impact is very prominent, at this time, you can fully consider the CDN server, such as Google Copy, which for the performance of the site a great help!

You only need to call when the following is used:

    1. <script type="Text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" > </script>

3. Using the cdn-hosted version but no backup measures

Although we believe that Google is very good, there is no problem, but don't forget you in the kingdom, everything is possible! Therefore, it is necessary and simple to add the local server version of the disaster recovery plan to the HTML code:

    1. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
    2. <script>window.jquery | | document.write (' <script src= ' js/libs/jquery-1.7.2.min.js ><\/script> ') </script>

4. Forget the chain style

When we are doing some normal operations, we can improve performance without loading elements multiple times if we use chained operations. For example

    1. $ ("#mydiv").    Hide ();
    2. $ ("#mydiv"). CSS ("padding-left", "50px");
    3. jquery gets elements 2 times
    4. $ ("#mydiv"). hide (). css ("padding-left", "50px");

Once done, sometimes the chain-style performance improvement is quite impressive oh

5. Forget the cache

This is an important performance-related tip: Don't forget to cache! If you call an element at least 2 times in a page, you should consider caching. A variable allows you to cache selectors in jquery. When you use the selector for the second time, you simply reference the variable. The advantage of this is that jquery does not have to traverse the entire DOM tree again to find the element you choose. For example

    1. var $myMxria = $ ("#mydiv"). Hide ();
    2. //......
    3. $myMxria. Show ();

6. Why not use the original JS?

Used to the $, we basically ignore document.getElementById, but have to say, misuse of $ is also wrong, why? If it is purely a property modification, using the original JavaScript performance is better, without using jquery objects at all. For example, in the following example, the browser will convert the jquery object into a DOM node.

    1. $mydiv [0].setattribute (' class ', ' awesome '); This kind of writing is a bit of a performance cost.

7. Abuse plugins that are not checked

Today, jquery has also brought countless plugins, wonderful, shocking plug-ins a lot. We like to follow the trend and use some fashionable stuff. But in fact, many plugins need to be carefully evaluated to see if it is the right project for you, or do you really need it? Have you considered the following factors?

File size: Over 10k size you have to think about it a little bit.

Performance evaluation: Easy to do not care about the performance of diagram? Are you sure?

Cross-browser support: see what browser your customers are using, don't forget the old IE6 but still elegant

Mobile support: Verify that the plugin is functioning properly in the mobile environment

8 without jquery

No, no, no. Why do you have to use it? Many times we may not have thought of this problem at all, the first thought may be with Jquey seems to be easy to achieve AH! This misunderstanding is really common, do you have a sharp knife cut to the end of the habit?

9 using jquery to do server-side live

jquery is too good, too strong, it seems that everything can be done at the front! As a result, we go into a myth: a job like validity checking and data validation that ignores the importance of being on the service side. A lot of business logic in the front-end processing of an ancient brain in the front-end processing, the tragedy of the over-the-edge of this happened! Be sure to remember that anything can happen in the front-end browser!!! Disable JS, an incompatibility problem, fake data, attack behavior, these are not 100% of developers can control, so the service side of the live do not because of the power of jquery to relax vigilance!

The above for reference, see if you have entered the erroneous zone?

Original link: http://webdesignledger.com/tips/9-jquery-mistakes-you-shouldnt-commit

9 Myths about using jquery

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.