15 ASP skills

Source: Internet
Author: User

* Tip 1: Use GLOBAL. ASA for the application layer File
Load the file into an application layer array in GLOBAL. ASA, instead of reading the file on the page by using an ASP file system object.
GLOBAL. ASA can be used to specify event scripts or declare objects with a session or application scope. It is not directly displayed to users, but stores information and objects of application-layer events. Then, you can point to the application-layer array containing data through the page. This means that each server sends a request to read a file, instead of reading each page. You can run an independent ASP file to refresh the content of the application layer array, and you can also consider using a dictionary image (see Tip 9 ).
This technique can greatly speed up your system.
How can we implement this technique?
If you are a script writer, you must use the File System Object to read files and put them in an array or a dictionary object. Then read the file in GLOBAL. ASA and put the Array (put the file content you have read) or dictionary object to the application layer declaration. In this way, you can access information in an array or dictionary object without submitting information through an ASP request each time.
But you may wonder, "What if the content in the cache needs to be updated? I bet I won't use it. "Actually not. If the content in the cache needs to be updated, you can call an ASP file containing only the Administrator's access to the script that can execute the lock command of the application, and update the cache information in the array or dictionary object, finally, execute the application lock command.
* Tip 2: Remove HTML comments from the product source code (applicable to IIS3.0)
Good, hard to write is certainly hard to understand. Just kidding. This doesn't mean that you need to remove all HTML comments (script comments are good). A wide range of HTML texts can be copied to the client in batches. In this way, your script will run faster on IIS3.0 (in IIS4.0, HTML annotations will no longer lead to lower execution speed ).
* Tip 3: multiple Response. write statements
If you write the output results in the format in several places in the code, consider combining these results and writing them out with a Response. write statement. Then you can look at the composition of your HTML code and vbscript. Do not spread HTML and vbscript too open. Try to write HTML and vbscript into blocks.
* Tip 4: Use the <OBJECT> flag to show the OBJECT
If you need to point to objects that may not be needed, use the <OBJECT> flag for example, instead of the Server. createobject. use Server. createobject will generate this object immediately. If you do not need it in the future, it will be a waste of resources.
* Tip 5: Use local variables whenever possible
(The following new tips Replace the "define variables in a row" released earlier, which contains some incorrect ideas ):
Local variables are defined in subprograms and functions (that is, variables with local ranges). These variables are compiled into numbers and pointed to and placed into a table. The point of these local variables can be compiled once. Global variables are executed at runtime. This means that local variable access is several times faster than global variables. In addition, multi-dimensional global variables are the slowest among them. When a multi-dimensional global variable is used for the first time, an object with the same name must be searched in the entire object model before a new object is generated.
The following is a common example:
Foo. bar. blah. baz = Foo. bar. blah. qaz (1)
If Foo. bar. blah. zaq = Foo. bar. blah. abc then
The following results are generated during running:
1) The Foo variable is defined as a global variable. 2) the bar variable is defined as a member of Foo. 3) the blah variable is defined as Foo. A member of bar 4) variable qaz is defined as Foo. bar. A member of blab 5) calls Foo. bar. blah. quaz (1) 6) repeats 1 to 3. The system does not know that if the call to qaz changes the object model, step 1-3 must be re-executed. 7) baz is defined as Foo. bar. members of blah, output value 8) Repeat 1-3, execute zaq9) Repeat 1-3, execute abc
As you can see, the efficiency is extremely low. The fastest way is to write the code in vbscript:
Set myobj = Foo. bar. blah' do the resolution of blahoncemyobj. baz = myobj. qaz (1) If Myobj. zaq = Myobj. abc then
* Tip 6: Avoid repeatedly defining arrays.
When Using dim, avoid redefining the array. Because you may need to use redim to redefine the size of the array. For such an operation, if your machine memory is not very large, it is best to consider the worst plan to set the length of the array or set the length of the optimal state at the beginning, use redim only when necessary. Of course, this does not mean to increase the memory, if you do not need it.
The following example illustrates the improper use of redim.
In fact, myarray (5) is defined at the beginning, and redim will be used to increase its size in the future, which may occupy some memory, but the speed will be much faster.
* Tip 7: Avoid public (global) variables
Do not use variables defined with public. If you are writing vbscript or accessing variables in ActiveX controls or java applets, avoid public variables as much as possible. The public keyword is usually designed for future use. Since public cannot bring you any benefits, it is best to use dim.
* Tip 8: use an absolute path
If possible, avoid using relative paths instead of absolute paths. To use the relative path, IIS needs to return to the current server path, which means that the execution speed of special IIS requests is low.
Note: It is much easier to use relative paths to port data.
* Tip 9: Use a "Dictionary" pair
The dictionary object provided in VBScript can provide quick search and storage of any data with keywords. You can use a dictionary object to access various data in the Array Based on keywords, so that you can quickly find discontinuous content in the memory (because you are specifying the keywords you are using, instead of knowing the location where the object is stored in the array ). If you want to search for non-linear keyword data, it is much faster to use a dictionary object.
However, if the keyword data is continuous in the memory, the array will be faster in searching and storing data. At the same time, it should be noted that index creation in dictionary is slower than in array. You should choose the best data structure for you.
* Tip 10: Make full use of the browser's rollback function
If you are using a smart browser, it will help you do a lot of rollback work, as long as you need it, you may wish to use it more. If any errors occur, you can return to the front and access the database from the back. But remember that when you access the database on the server, you need to perform an operation on the database. If there are many variables in the form you want to return, it is a bit difficult. If you know that you need to execute a lot of code on the client, move the code to the client to speed up execution. When you are running on the client, the processor is yours. The server has to use its own processing capabilities to process the requests it receives.
There is also a good way. If you use a lot of server-side scripts and have a lot of conditional input in the form, you 'd better put the code that triggers the response in the client script engine (such as vbscript, javascript ). Ignore this and the server code runs faster, because the unnecessary code is not sent to the server for execution. Of course, this is only applicable to small codes. It is not suitable for large codes.
* Tip 11: Avoid using server Variables
When you access data through server variables, You need to request the server from the web, and then collect all server variables, not just the variable you requested. This is similar to finding something specific from the box in the moldy attic. When you are looking for something, you must first find the box in the attic. The same is true for the server when you request a variable. When you request a variable, it triggers the execution and then requests the variables that do not cause the execution point.
* Tip 12: Use "option explicit"
Write it in the asp file. Unlike c, vb allows you to use a variable before it is forcibly defined. Enable option explicit to help you identify variables that are not defined. If you use unspecified variables, an error message is displayed. At the same time, it can also make those unstated local variables invalid. Unstated local variables are as slow as global variables (twice as slow as defined local variables ). Opening option explicit will naturally help you remove these bugs from your code.
* Tip 13: copy the collected value to a local variable.
If some values are used repeatedly, copy these values to the client as local variables. Every time you use these values, you can find them in the pile of values, which speeds up script running.
* Tip 14: exercise caution when using the session object
Session objects can be used to store special user information. When a user jumps between different pages of the application, the variables stored in the session will not be lost. On the contrary, these variables will be retained throughout the user process. When a page is requested by a user without a session, the web server automatically creates a session object. When the session time limit is reached or is interrupted, the server will cancel the session object. To avoid this situation, you can disable the session attribute. However, the session attribute in each application in iis3.0 cannot be closed. Disabling sessions on the server will be faster, but this will result in a loss of many features. It is best to use the session object with caution when necessary.
When you use the session object throughout the application, be sure to use it quickly. Otherwise, the session object will be reset. In iis4.0, the session Status in the basic application can be activated or canceled in the specified. asp file.
* Tip 15: perform a performance test
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.