Seven Sins of AJAX application development

Source: Internet
Author: User

AJAX bandwagon is a good place to go. It brings you faster, more efficient, and more dynamic applications. But it also has its own shortcomings.

At first glance, it seems that some common sense can avoid these defects. To some extent, this is true. However, from the perspective of the origins of DHTML, AJAX applications are full of structural differences. No matter how much common sense you have in application development, it is also good to learn from others' mistakes. We call these errors "seven deadly sins", but they cannot represent all errors.

In fact, before you commit these fatal mistakes, you may first make some minor mistakes. So let's start from here. This is a mistake that everyone may make. These errors are so common that you can find most of them through Google search.

Seven minor sins

1. abuse the Back button

This is a mistake that everyone will make. The Back button has become your expectation in many web applications. Many new AJAX developers use the Back button for multiple reasons when developing AJAX applications. First, JavaScript is not the most friendly language for it. Second, AJAX design requires a new way of thinking.

It is obviously not the best choice for AJAX developers to "back. "Back" is a feature that you use to update a page, or more frequently. You need to "undo" a page in a specific situation. Recognize this before coding, or you may duplicate your work.

2. forget to tell the user about the current situation.

One part of AJAX's working principle is that it does not use conventional web page user interfaces to load programs. Therefore, you need to clearly design some visual prompts so that users can understand what is happening.

3. Ignore links

This is also the standard error of AJAX: the URL link that can be cut by external users of the program is missing. How many times have we copied URL links and sent them to others? When you use AJAX, the only way to provide useful URL links to your users is to manually provide them. Why? In the AJAX program, the server does not provide the page dynamically generated by JavaScript! Do not ignore the most common features in this network application that your users may be interested in. Since the server does not support it, you need to make some effort to provide users with URLs.

4. Use content control instead of control

If you are looking for dynamic content control, it is a good thing for you to break through the interaction between traditional customer servers. But this is also a sin: it is indeed well controlled when the content on a precise location of a page is rewritten to adjust the user's interactive experience, however, this will make your page incomplete. Generally, we focus on processing a part of a page and forget that the server does not refresh the page. This will lead to messy pages and lower user experience. When they look at the page, they may see outdated pages! Focus your attention on the entire page; Make sure that the content of the dynamic page is updated.

5. Exhausted spider

The advantage of AJAX is that it can provide a large amount of text to the page without reinstallation. The defect of AJAX is that it can provide a large number of text to the page without reinstallation. If the application is set to be friendly to search engines, you can imagine what will happen. No matter what appears on the page, be sure to implant stable enough text on the top to play for the spider.

6. Generate Garbled text

AJAX does not support many character sets. This does not involve the limitations of life and death, but forgets that it can produce real problems. The most basic character set is the UTF-8. No matter what JavaScript sends, do not forget to encode it correctly and set the server-side character set based on the content.

7. No prompt is provided for users who use browsers that do not support JavaScript.

Some browsers do not support JavaScript, and users cannot understand what is happening at the moment. Please give them a prompt.

To be honest, most of them are common sense issues. Real problems are easily overlooked.

Seven fatal AJAX sins

1. Memory leakage

Anyone who has been engaged in development for a long time knows about circular references and the dangers they bring to memory management.

AJAX uses the memory management language. This means that JavaScript has the built-in information package collection function, so it can extract variables that are no longer used by reference paths and re-allocate the memory used by these variables.

It works well as a basic working principle, but when the model object and the view element reference each other, because of these loop references, you cannot rely on this function to optimize your memory usage. In principle, if the object is zero, the element is zero. However, if the elements are referenced backward from the object, the information package collector will not touch these objects.

Now the problem arises: In the file object model, DOM nodes in any file tree may be referenced by other elements in the tree, whether or not they are referenced by other objects! Therefore, any objects marked by DOM nodes in the information package collector must be empty in this direction, or their memory will remain in the allocated State.

2. Do not understand the meaning of "Asynchronous"

Asynchronization can easily make users who are not familiar with it feel nervous. However, if the web applications you designed for these users are desktop applications, they will certainly not feel uneasy. This is a crucial design point. Most Web applications have similar functions as desktop copies. However, in Web applications, users expect this illusory feature to make them completely different.

Users have very different prejudices and expectations when dealing with Web browsers, but they do not have such behavior in desktop applications. Therefore, although the frequent response between the page and the server is very good and efficient, the page can be modified at the same time, but this will make the user dizzy. Therefore, you need to abide by the two rules and consider every change that falls into the user's visual scope: if it is not an urgent update for the user, the upgrade should be more gentle and will not be transferred; if updates are important to the interaction between users and applications, they must be clear and obvious.

3. Keep the server in the dark

Reducing the communication between the client and the server is a major problem, but this was not the case before. In the past, the server-side applications knew all the situations and were able to see all the situations: every exception, every reload, every event can be seen and recorded, of course, the server also knows what the client is, because the server records everything displayed on the screen.

This is not the case in AJAX applications. When an event occurs, these events are independent from the server. That is to say, when the client encounters a problem, the server does not know it immediately. Detects and records events and exceptions on the client at a certain location, so that the server can track problems requiring interference as soon as possible.

4. GET laziness

GET is used to retrieve data again; POST is used to set GET. Do not use GET when it is inappropriate, even if you think it is harmless. The GET operation changes the status, and the link that changes the status may confuse users. Most users think that the function of the link is navigation rather than function.

5. incompatible data types

JavaScript is not part of the. NET Framework. Although this is really sad, it presents a problem we may encounter: Determine that JavaScript can understand the data types on its running platform, and vice versa. NET or others. There may be multiple converters. You need to find them. For example, the Ajax. NET Pro database provides a converter that can convert. NET and JavaScript Object symbols.

6. Some applications do not know when to close

You do not need to refresh the page to dynamically generate content. If you do not close the page, it will be very bad.

How many web pages have you seen longer than the proceedings of the US Congress? If the web page is infinitely extended, it will undoubtedly be a nightmare for the user. Just think about what the user will think of the application that never stops. Make your network application dynamic, but it must be within the feasible limits.

7. Keep your JavaScript away from your DOM

Remember that AJAX is built on the Model-Visual-Control Model-View-Controller structure. Take this seriously. JavaScript is a model layer, DOM is a visual layer, and controllers are their marriage consultants. Make sure that your network files are independent of JavaScript, which is beneficial to users who do not support JavaScript. In addition to the content itself, it is meaningful and operable only when users use JavaScript. In this case, use JavaScript to create the content. Original International)

Related Articles: Will Ajax be HOT or OVER tomorrow?

Related Article

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.