Optimize ajax to reduce website load

Source: Internet
Author: User

  

Recently, I mainly helped a team test and optimize the project. It may be because most of the participants in the project are new users and they are not very familiar with Ajax, resulting in abuse of Ajax controls, this article mainly summarizes some of the problems we have encountered recently and discusses them with you. We hope you will not pay enough for them. I also hope that many experienced developers can provide guidance.

The following are my two experiences based on my problems:

1. Use updatepanle in different situations

First, use the <triggers> </triggers> attribute of updatepanle to directly set the events of related controls on the page, this method is used to simply use updatepanle or the same tab page on the same page.

 

Second, when multiple tab pages exist on the same page and events on different tab pages are associated, it is generally applicable to the background code registration method. Because the updatepanle on one tab page may not be able to recognize or find the trigger event of another tab control, it is easy to cause an error because of the type of the tab control you selected, I used a third-party tab control, but Microsoft or other third-party tab controls do not work. Although the latter may solve this problem in the future, but to make your program run properly, using code registration is a wise choice.

 

For example, a page you designed has multiple tabs, and an event of a control in a tab page triggers an asynchronous update event of another tab page, it is better to use the code to register the updatepanle update event.

The specific implementation code is as follows, which is also very simple:

Register the asynchronous update trigger control with scriptmanager1 in page_load.

Scriptmanager1.registerasyncpostbackcontrol (btnadd );

Then, call the method to be updated in a trigger event of btnadd,

After the event is executed, call the updatepanle of the update area to execute the update () method. 2. Minimize the use of multiple updatepanle controls on the same page (or tab page)

Upatepanle can reduce the communication burden between pages and servers, but abuse of upatepanle will increase the communication burden between pages and servers. using too many updatepanle on the same page will lead to multiple communications, for example, an event source triggers multiple update events.

Generally, you only need to use one updatepanle In The Same tab or table on the same page. Even the control that does not need to be updated can be placed in the same updatepanle, you only need to set autopostback to false if the event is not triggered. Naturally, special treatment is required in special cases due to business needs.

Therefore, if it is not a special business requirement, try to put multiple controls that require asynchronous updates in the same updatepanle to unify asynchronous updates and reduce the number of page round-trip communications. As for unified asynchronous updates, the Business appearance layer (that is, the page layer) can be solved with table, and the Business Code layer (corresponding page background code) can be optimized according to business needs.

 

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.