Home > Web Front-end > JS Tutorial > js performance optimization skills_javascript skills

js performance optimization skills_javascript skills

WBOY
Release: 2016-05-16 15:29:07
Original
1168 people have browsed it

Performance optimization: In short, it is to make the system run faster and take less time to complete specific functions without affecting the correctness of the system's operation

http:hypertext protocol

Its top layer is the application layer, transport layer, network layer and physical layer
Request information: request line, request header, blank line, message body
Response information: status line and status code

Use the ToString method of value type:

When concatenating strings, the " " sign is often used to add numbers directly to the string. Although this method is simple and can get correct results, due to the different data types involved, the numbers need to be converted into reference types through boxing operations before they can be added to the string. However, the boxing operation has a greater impact on performance, because when performing this type of processing, a new object will be allocated in the managed heap, and the original value will be copied to the newly created object. Using the ToString method of a value type improves application performance by avoiding boxing operations.

Try to choose html controls:

The functions that can be implemented on the client are implemented on the client (proficient in JavaScript), reducing the pressure on the server. Data control selection order: Repeater, DataList, DataGrid.

After establishing a database connection, open the connection only when operations are really needed, and close it immediately after use, thereby minimizing the time the database connection is open and avoiding exceeding the connection limit.

String operation performance optimization

(1) Use the ToString method of value type.

When concatenating strings, the " " sign is often used to add numbers directly to the string. Although this method is simple and can get correct results, because it involves different data types, the numbers need to be converted into reference types through boxing operations before they can be added to the string. However, the boxing operation has a greater impact on performance, because when performing this type of processing, a new object will be allocated in the managed heap, and the original value will be copied to the newly created object. Using the ToString method of a value type improves application performance by avoiding boxing operations.

(2) Use StringBuilder class

String class objects are immutable. Reassignment of a String object essentially recreates a String object and assigns the new value to the object. Its method ToString does not significantly improve performance. When working with strings, it's best to use the StringBuilder class, whose .NET namespace is System.Text. This class does not create new objects, but directly operates on strings through methods such as Append, Remove, and Insert, and returns the operation results through the ToString method.

Avoid unnecessary round trips to the server

Use Page.IsPostBack to avoid unnecessary processing of the round trip.
Although you most likely want to take advantage of the time- and code-saving features of the Web Forms page framework, there are some situations where using ASP.NET server controls and postback event handling is inappropriate. Typically, you only need to initiate a round trip to the server when retrieving or storing data. Most data operations can be performed on the client during these round trips.

Compress js

The case of js calls in the page should be consistent to avoid different files being cached. If the js on the page is available, write it as a unit file and call it. Use less jpeg for pictures and use gzip to compress web pages to speed up page display.

Write the calling js at the bottom of the page as much as possible, and the viewstate can also be rewritten to the lower part of the page, or the viewstate can be compressed. The condition is that viewstate must be used.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template