Introduction and application testing of several compression modules optimized by gzip on the ASP. NET page! Page 1/2 (with source code)

Source: Internet
Author: User

Before the introduction, let's talk about ASP. the role and working principle of the gzip compression module on the Net Server. Many people use a large number of JS special effects or place a large number of dynamic advertisements when writing a webpage, usually some compression tools are used to locally compress pages or scripts and then upload them to the server. However, such compression tools generally have limited compression ratios and are not obviously optimized. Article The function of the compression module is to perform high-strength gzip compression on pages, scripts, and other resources of Asp.net (generally compressed to only 1/5 of the size ), in addition, the compression process occurs when the client requests the ASPX page, which is compressed by the server and then transmitted to the client for display. In other words, after the project uses these compression modules, all aspx pages do not need to be compressed in advance. Instead, the compression module automatically compresses the page in the server background when the page is requested for the first time by the client (the compression process takes a short time, it is almost negligible, but the page loading speed after compression increases significantly ). The following describes several compression modules that implement such functions:

1. webresourcecompression compression module
This compression module is used to compress ASP in real time. all *. axd resources. Generally, when the ASPX page uses Ajax frameworks such as anthem.net or the Asp.net verification control, axd file references are generated. This file is actually a JS script. After this compression module is enabled, all axd resources are compressed by gzip and then sent to the client. This module is especially suitable for projects where the ASPX page applies the Ajax framework or the large axd resource file needs to be referenced!

Use: Decompress the package and place webresourcecompression. DLL to the bin directory of the website project. In the Web. config CopyCodeThe Code is as follows: <Add name = "webresourcecompression" type = "webresourcecompression. webresourcecompressionmodule"/>

Advantage: easy to use
Disadvantage: Only ASP. net2.0 or later versions are supported. Other resources except axd cannot be compressed!

Ii. pagecompression compression module
Unlike previous modules, this module is used to compress the ASPX page. After this compression module is enabled, the ASPX page will be compressed in real time, generally, KB of pages can be compressed to about 25 KB. This module is applicable to projects that only need to compress pages!

Use: Decompress compression. pagecompressionmodule. DLL to the bin directory of the website project, and add the following statement to the Web. config Copy codeThe Code is as follows: <Add name = "pagecompressionmodule" type = "compression. pagecompressionmodule, compression. pagecompressionmodule"/>

Advantage: easy to use
Disadvantage: Only ASP. net2.0 or later versions are supported. Other resources except the ASPX page cannot be compressed. After compression is enabled, the axd resources referenced on the page will be invalid (Bug )!

Iii. httpcompress6.0 compression module
This is an ASP. net1.0/1.1/2.0 (versions earlier than 2.0 do not support gzip compression, only deflate compression), can compress all types of resources requested by the ASPX page (mimetypes, including images, JS scripts, axd, aspx pages, and CSS files. in config, you can customize the types of resources to be compressed, the types of resources not compressed, or the specified pages to be compressed or not compressed, there are also powerful custom functions such as setting the compression ratio (high | normal | low). However, the most serious problem with this control is in ASP. enabling compression in net2.0 will invalidate the axd file, so that if the Ajax framework is applied on the page, the Ajax function will become invalid.

Usage: omitted (similar to the compressionmodule compression module recommended below)
Advantage: opennessSource code, Powerful custom function, supports ASP. net1.0/1.1/2.0, can compress a variety of resources!
Disadvantage: complicated use. Enabling compression under ASP. net2.0 will invalidate the axd file!

Iv. compressionmodule compression module (strongly recommended)
One module recommended by myself can also compress all resources requested by the ASPX page and compression modules that support powerful custom functions, like httpcompress6.0, you can customize the types of resources you want to compress and do not compress those types of resources. You can also define whether to compress the specified page or not to compress the specified page, in addition, the cache Resource function and the powerful function of the specified compressed directory are enabled. In addition, there will be no bug like httpcompress6.0 that the axd file is invalid, this compression module can perfectly support various Ajax frameworks !!

Usage: see the compressionmodule for actual use and performance testing!
Advantages: open source code, powerful custom functions, ability to compress a variety of resources, and perfect support for various Ajax frameworks!
Disadvantage: complicated use. Only ASP. net2.0 or later is supported!

To sum up, various compression modules can optimize pages. However, since the compression process occurs at one end of the server, enabling these compression will consume a little server resources, however, in general, the compression only occurs when the client accesses the page for the first time. Because the browser caches the page and resource relationships, the server resources will not be used for compression when the access is refreshed again, therefore, for developers who have a huge website page size, enabling the compression function is definitely worth some money. After all, the page size is smaller and loading will be faster!

Appendix: compressionmodule compression module instructions and performance tests!
I. Use
First, put DC. Web. httpcompress. DLL to the bin directory of the website project, and add and modify the Web. config of the Project as follows:

Copy code The Code is as follows: <configsections>
<Sectiongroup name = "dcweb">
<Section name = "httpcompress" type = "DC. Web. httpcompress. configuration,
DC. Web. httpcompress "/>
</Sectiongroup>
</Configsections>

<Dcweb>
<Httpcompress compressiontype = "gzip">
<! -- Set whether to enable cachefiles and specify the cache directory. If this line of configuration is deleted, the default value is false (no cache is enabled). -->
<Cachesetaskcachefiles = "true" Path = "cache"/>
<! -- Set jspath and csspath. If this line of configuration is deleted, the default value will be used. -->
<Pathsettings jspath = "JavaScript" csspath = "CSS"/>
<! -- Configure the type of resources to be compressed. Here, only HTML is compressed, that is, only the ASPX page and *. axd resources will be compressed, and other resources (slice, CSS, etc.) will not be compressed! For example, if you want to compress a GIF image, add <add mime = "image/GIF"/> and <add mime = "image/JPEG"/> -->
<Shortdedmimetypes>
<Add mime = "text/html"/>
</Includedmimetypes>
<! -- Use the following to configure which types of resources are not compressed:
<Excludedmimetypes>
<Add mime = "text/html"/>
</Excludedmimetypes>
Note: Only one excludedmimetypes and includedmimetypes needs to be configured. If excludemimetypes is configured as above, other resources except HTML resources will be compressed -->
<Excludedpaths>
<! -- Set the page path for which compression is not enabled. The default. aspx page in the nocompress directory is set below. The compression function is not enabled for other pages. -->
<Add Path = "~ /Nocompress/default. aspx "/>
</Excludedpaths>
</Httpcompress>
</Dcweb>

<! -- The JS. axd and CSS. axd must be enabled to allow JavaScript and CSS
Compression -->
<Httphandlers>
<! -- If you do not need this function, you can delete this configuration section. -->
<Add verb = "*" Path = "Js. axd, CSS. axd"
Type = "DC. Web. httpcompress. compressionhandler, DC. Web. httpcompress"/>
</Httphandlers>
<! -- The compression module must be enabled for the webresource. axd to be
Compressed -->
<Httpmodules>
<Add name = "scriptmodule" type = "system. Web. Handlers. scriptmodule,
System. Web. Extensions, version = 1.0.61025.0, culture = neutral,
Publickeytoken = 31bf3856ad364e35 "/>
<! -- Set the parameters for enabling the compression module -->
<Add name = "httpcompressmodule"
Type = "DC. Web. httpcompress. httpmodule, DC. Web. httpcompress"/>
</Httpmodules>

After configuration, the compression module will work normally!

TIPS: If Web. config is configured
<Cachesetaskcachefiles = "true" Path = "cache"/>
The cache directory must exist in the project. Otherwise, an error will occur. If the project does not want to add this directory, you only need to delete this configuration section!

2. Performance Tests for actual applications

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.