This article will share with you how to speed up Website access, including server configuration recommendations, ASP. NETCodeWriting and optimization of front-end pages, etc., not bad.
I. Server Optimization
L Windows series:
- 64-bit win2008r2 + hpyer-V + Server Load balancer + iis7.5
- 64-bit win2003 + Virtual Machine + Server Load balancer + IIS6
- Prohibit the server from accessing the Internet. Disable unnecessary ports.
- Remove all permissions for each disk and retain only the full control permissions of the Administrators group and system.
- Iis7.5 uses applicationpoolidentity to identify the directory permission User: IIS apppool \ site name
- IIS6 needs to create independent users for each site and set separate permissions for IIS users.
- Disable Logging in IIS.
Ii. Database Optimization
L 64-bit mssql2008:
- Use less triggers, cursors, and foreign keys. Use multiple Storage Processes and views. A proper amount of index queries will increase the speed. Each table should have no more than three indexes.
- Check the deadlock process and wait process at regular intervals, clear the process, and correct the source of the deadlock in time.
- Complex statistical reports must be run with plans.
- To query the number of records, use count (0) instead of Count (*).
- Do not use * for table fields during select *. * It is slow to query all fields.
- If the field is an index column, you can use Union all to replace or to query it using the index line.
- Paging query is required for a large record set.
- Do not use the text/ntext type. Use varchar (max)/nvarchar (max ).
- Try not to use temporary tables. Use the table type or embedded view.
Iii. backend Optimization
L use dbdatareader instead of datatable/dataset to read data.
L for (INT I = 0; I <DT. Rows. Count; I ++) should be written as follows:
For (INT I = 0, Len = DT. Rows. Count; I <Len; I ++) or
Foreach (datarow info in DT. Rows) recommends this method.
L use try catch less, and use try catch with finally.
L use using more, for example:
Using (dbdatareader DR = data. getdbdatareader (strsql) {While (dr. Read ()){};}
L for large string operations, use stringbuilder to use less string, compare for string comparison, Concat for string addition, and stringbuilder append for large string addition.
L variables must be defined first and not in a loop. For example:
Incorrect syntax: For (INT I = 1; I <10; I ++) {string S = I. tostring ();}
Correct syntax: String S = string. Empty; For (INT I = 1; I <10; I ++) {S = I. tostring ();}
Note: When adding strings, if there is an int type, convert it to the string type before addition to reduce unnecessary binning operations.
L if you are using an HTML control, disable <% @ page enableviewstate = "false" autoeventwireup = "false" enablesessionstate = "false", Web. config <pages enableviewstate = "false" enablesessionstate = "false"/>
L use foreach instead of
L use the stored procedure/view to operate the database.
L use the cache to cache data. This is the key. Net: httpcontext. Current. Cache/httpruntime. cache, shared cache with velocity/memcached
L <% @ outputcache duration = "60" can be used to cache the page, and response. bufferoutput = true;/<% @ page buffer = "true" can be used to buffer the output.
L The site can be generated to generate static surface pages, with many benefits.
L URL can be rewritten to pseudo-static to provide the RSS/Baidu-sitemap/Google-sitemap service, which is conducive to search engine inclusion.
L use. ashx for Ajax call pagesProgramThe speed is faster than that of the. aspx file. Do not use get for Ajax requests that require post.
L release the dll version when releasing the site. Do not use the debug version.
L IIS must use the integration mode instead of the Classic mode.
L web. config and <customerrors mode = "on"/> disable the error message.
L web. config and <compilation DEBUG = "false"/> disable the debugging mode.
L replace response. Redirect with server. Transfer
L use more generic set operations and use less arraylist.
Iv. frontend Optimization
L it is best not to use the net control, HTML control, and CSS + Div layout on the page.
L use JSON + Ajax for data interaction.
L learn to use jquery to improve development speed.
L use the
L combine multiple CSS Background images into one image to ensure that the size of the merged image cannot exceed 50 kb. JavaScript files can be merged into a JS file and then compressed using closure_packer_yui_compiler. This reduces the number of client connections.
L JavaScript code segments should not be placed on HTML pages. They should be placed in independent JS files. The advantage is that JS files can be CDN/cached.
L place the CSS file between
L website images, CSS, JS, materials, and resources can be placed on an independent site for CDN acceleration. Second-level domain names have cookies. It is best to use first-level domain names.
L title/ALT must be added to the tag and IMG tag, and title/keywords/description/RSS/sitemap must be added to the
L you can enable gzip compression on the page.
L install the FF plug-in "yslow/Page speed ".