1. Use the http module to control the page lifecycle.
2. Customize response. filter to get the static content (disk cache) of the dynamic page generated by the output stream ).
3. gzip compression on the page.
4. outputcache program outputs the page cache.
5. Delete blank strings on the page. (Similar to google)
6. Completely Delete the viewstate.
7. Delete the junk namingcontainer generated by the server control.
8. Use scheduled tasks to generate pages on time. (This article does not include the implementation of this practice)
9. js, css tutorial compression, merge, cache, image cache. (This article does not include the implementation of this practice)
10. cache corruption. (Excluding implementation of 9th practices)
In response to the above practices, we first need an http module, which is the portal and core of the entire page process.
1. Customize response. filter to get the static content of the dynamic page generated by the output stream (disk cache)
The following code shows that we use request. rawurl is the basis for caching, because it can contain any querystring variable. Then, we use md5 encryption to obtain the variable of the local file name on the server, and instantiate a fileinfo to operate the file, if the last file generation time is less than 7 days, we use. the transmitfile method added by net2.0 sends the static content of the stored file to the browser. If the file does not exist, we will pass the stream Obtained by response. filter to the commonfilter class and use filestream to write the dynamic page content to the static file.
Ii. Page gzip Compression
Gzip compression on pages is one of several major practices for explaining high-performance web programs in almost every article, because gzip compression can reduce the number of bytes sent by the server, this allows customers to feel that the webpage speed is faster and bandwidth usage is reduced. Of course, the client browser also supports it. Therefore, if the client supports gzip, we will send the content compressed by gzip. If not, we will directly send the content of the static file. Fortunately, modern browsers such as ie6.7.8.0 and Firefox support gzip.
To implement this function, we need to rewrite the above application_beginrequest event:
Iii. outputcache Programming Method output page Cache
Asp tutorial. net embedded outputcache cache can cache content in three places: web server, proxy server and browser. When a user accesses a page set to outputcache, The asp.net tutorial writes the result to the output cache after msil, and then sends the result to the browser. When the user accesses the page in the same path, asp.net will directly send the cached content without passing through. the process of aspx compilation and execution of msil. Therefore, although the program's own efficiency is not improved, the page loading speed is improved.
To implement this function, we continue to rewrite the above application_beginrequest event. After transmitfile, We cache the page in this path in outputcache programming mode:
4. Implement commonfilter class to filter viewstate, filter namingcontainer, blank string, and generate disk cache files
We passed the stream object of response. filter to the commonfilter class:
First, we use the first stream write method to generate disk cache files. The Code is as follows. In these Code, only the initialization constructor, the write method, and the close method are useful, the filestream field is the operation object for generating static files:
5. cache corruption
After the implementation of the above program, the webpage has been cached on the client. If the user accesses the page cached by the website, the page will load the page at zero request speed. However, if some data is updated in the background, the foreground users cannot view the latest data in time. To change this situation, we must destroy the cache. Based on the above program, we only need to perform two steps to destroy the cache: update the temporary files on the server and delete the pages that have been replaced by outputcache.
To update a file on the server, you only need to delete this file. This file is automatically generated when a user visits this page for the first time. Of course, you can also delete the file with a program and then generate it:
// Update the file
To delete the cache items associated with outputcache, the Code is as follows. We only need to ensure that the parameters of this method indicate that the absolute path of the page is correct and that the relative path like ../cannot be used:
// Delete Cache