Js performance optimization tips _ javascript skills

Source: Internet
Author: User
Performance Optimization: in short, it requires faster running and shorter time to complete specific functions without affecting the system running correctness. This article introduces the js performance optimization skills, if you need a friend, refer to performance optimization: in short, it is to make the system run faster without affecting the system running correctness, and the time required to complete a specific function is shorter.

Http: hypertext protocol

Its top layer is the transport layer Network Layer Physical Layer of the application layer.
Request Information: request line request header empty line Message Body
Response Information: Status line and status code

Use the ToString method of the Value Type:

When connecting strings, you often use the "+" sign to directly add numbers to strings. This method is simple and can get the correct results. However, because different data types are involved, the numbers must be converted to the reference type through the boxing operation before they can be added to the string. However, the packing operation has a great impact on the performance, because during such processing, a new object will be allocated in the managed heap, and the original value will be copied to the newly created object. The Value Type ToString method can be used to avoid packing and improve application performance.

Select the html control as much as possible:

Functions that can be implemented on the client are implemented on the client (proficient in JavaScript) to reduce the pressure on the server. Data Control selection order: Repeater, DataList, and DataGrid.

After a database connection is established, the connection is enabled only when the operation is required. The connection is closed immediately after use, so as to minimize the time for opening the database connection and avoid exceeding the connection limit.

String operation performance optimization

(1) Use the ToString method of the value type.

When connecting strings, you often use the "+" sign to directly add numbers to strings. This method is simple and can get the correct results. However, because different data types are involved, numbers must be converted to reference types by packing them to be added to strings. However, the packing operation has a great impact on the performance, because during such processing, a new object will be allocated in the managed heap, and the original value will be copied to the newly created object. The Value Type ToString method can be used to avoid packing and improve application performance.

(2) Use the StringBuilder class

The String class object cannot be changed. In essence, the re-assignment of the String object re-creates a String object and assigns the new value to the object, the ToString method does not significantly improve the performance. When processing strings, it is best to use the StringBuilder class. Its. NET namespace is System. Text. This class does not create a new object, but directly performs operations on strings through Append, Remove, Insert, and other methods, and returns the operation results through the ToString method.

Avoid unnecessary round-trip to the server

Use Page. IsPostBack to avoid unnecessary operations on the round-trip process.
Although you may want to use the time-saving and code-saving functions of the Web forms page framework as much as possible, ASP. NET Server controls and sending back events cannot be used in some cases. Generally, you only need to start the round-trip process to the server when retrieving or storing data. Most data operations can be performed on clients during the round-trip process.

Compressing js

The case sensitivity of js calls on the page must be the same, so that different files are not cached. If JavaScript on the page can be used, the files written as units are called. Use less jpeg images and use gzip to compress webpages to accelerate page display.

Call js and try to write it at the bottom of the page. You can also rewrite the viewstate to the lower part of the page or compress the viewstate. The condition is that the viewstate must be used.

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.