Before the introduction, a simple say asp.net service side gzip compression module function and working principle, a lot of people write the page because of the use of a lot of JS special effects or put a lot of large dynamic ads caused the page or script bulky, Usually use some compression tools local to the page or script to a certain compression and then upload to the server, but such compression tool general compression rate is limited, optimization is not obvious, the compression module described in this article is the role of the ASP.net page or script resources such as high-strength gzip compression ( Generally compressed to only 1/5 of the volume, and the process of compression occurs when the client requests the ASPX page is compressed by the server and then sent to the client to display, in other words, after the project use these compression modules, all ASPX pages do not need to compress in advance, But by the compression module in the page was first requested by the client automatically in the backend of the server to compress processing (compression processing time quickly, almost negligible, but the compression of the page loading speed is increased significantly). Let me introduce some of the following to achieve this function of the compression module:
One, webresourcecompression compression module
This compression module is designed to compress all *.axd resources in real time for asp.net2.0 page references. General ASPX pages use such as Anthem.net Ajax framework or ASP.net validation control will produce Axd file references, this file is actually a JS script, enable this compression module, all AXD resources will be gzip compressed and then transmitted to the client, this module is particularly suitable for ASPX page application Ajax frameworks or projects that need to refer to bulky Axd resource files!
Use: After decompression, place the WebResourceCompression.dll in the bin directory of the Web site project, and add the following statement to the Web.config
Copy Code code as follows:
<add name= "webresourcecompression" type= "Webresourcecompression.webresourcecompressionmodule"/>
Advantages: Easy to use
Disadvantage: Only support asp.net2.0 or above version, can not compress other resources except Axd!
second, pagecompression compression module
Unlike the previous module, this module is designed to compress ASPX pages, after enabling this compression module, the ASPX page will be compressed in real time, the general 100K pages can be compressed to about 25K, this module is suitable for the page only to compress the project!
Use: After decompression, place the Compression.PageCompressionModule.dll in the bin directory of the Web site project, and add the following statement to the Web.config
Copy Code code as follows:
<add name= "Pagecompressionmodule" type= "Compression.pagecompressionmodule,compression.pagecompressionmodule"/ >
Advantages: Easy to use
Disadvantage: Supports only asp.net2.0 or above, cannot compress other resources except ASPX page, and when compression is enabled, the Axd resources that the page references will not be valid (bugs)!
three, HttpCompress6.0 compression module
This is a support asp.net1.0/1.1/2.0 (2.0 version does not support gzip compression, only supports deflate compression), can compress all types of ASPX page requests (mimetypes) resources, including pictures, JS scripts, Axd, ASPX pages, CSS files and so on, and can be web.config in detail to compress that type of resources and not compress that type of resources, you can also define to compress the specified page or do not compress the specified page, in addition to the compression ratio set (High|normal|low) and so powerful custom features, However, the most serious problem with this control is that enabling compression under asp.net2.0 causes the Axd file to become invalid, so that AJAX functionality is invalidated if the page applies an AJAX framework.
Use: Slightly (similar to the Compressionmodule compression modules recommended below)
Advantages: Open source code, powerful custom function, support asp.net1.0/1.1/2.0 version, can compress a variety of resources!
Disadvantage: The use of complex, asp.net2.0 to enable compression will cause Axd file invalid!
four, Compressionmodule compression module (highly recommended)
I recommend a module that can also compress all the resources of an ASPX page request and a compression module that supports powerful customizations, as well as HttpCompress6.0 to compress that type of resource and not compress that type of resource, or to compress the specified page or not to compress the specified page , and also has the ability to open cache resources and the ability to specify a compressed directory, and also will not be like HttpCompress6.0 will appear axd file invalid bug, so this compression module will be able to support the perfect variety of AJAX framework!!
Use: Please see the compressionmodule compression module in the back of the actual use and performance test!
Advantages: Open source code, a powerful custom function, can compress a variety of resources, can perfect support for a variety of AJAX frameworks!
Disadvantages: Use complex, only support asp.net2.0 or above version!
To sum up, a variety of compression modules can optimize the role of the page, but because the process of compression occurs at the end of the server, so enable these compression will consume a little server resources, but generally speaking, compression only occurs in the first time when the client page, because after the browser itself cache page and resource relationship , refresh the visit again will not occupy the server resources for compression, so for the Web page size of the developer, enable the compression function is definitely value for money, after all, the page volume is smaller, loading will be faster!
Appendix: Compressionmodule Compression Module usage instructions and performance test!
First, use
First, put the DC.Web.HttpCompress.dll into the bin directory of the Web site project, and then add and modify the items as follows Web.config
Copy Code code as follows:
<configSections>
<sectiongroup name= "Dcweb" >
<section name= "httpcompress" type= DC. Web.HttpCompress.Configuration,
DC. Web.httpcompress "/>
</sectionGroup>
</configSections>
<DCWeb>
<!--set whether to enable Cachefiles function, and specify the cache directory, if deleted this line of configuration automatically defaults to False (do not turn on cache)-->
<cachesettings cachefiles= "True" path= "cache"/>
<!--set Jspath and Csspath, the default value is used if you delete this row configuration-->
<pathsettings jspath= "javascript" csspath= "CSS"/>
<!--Configure what types of resources to compress, where the HTML is set to compress only, that is, only ASPX pages and *.axd resources will be compressed, and other resources (such as images, CSS, etc.) will not be compressed! Example: If you want to compress an GIF, add <add mime= "Image/gif"/>, and compress jpg to add <add mime= "Image/jpeg"/>-->
<IncludedMimeTypes>
<add mime= "text/html"/>
</IncludedMimeTypes>
<!--configure which types of resources are not compressed use:
<ExcludedMimeTypes>
<add mime= "text/html"/>
</ExcludedMimeTypes>
Note: Excludedmimetypes and includedmimetypes only need to configure one, and if Excludemimetypes is configured like the above, it means that other resources will be compressed except HTML-type resources-->
<ExcludedPaths>
<!--set the page path that does not enable compression, the Default.aspx page under the Nocompress directory will not enable compression, but other pages normally enable compression-->
<add path= "~/nocompress/default.aspx"/>
</ExcludedPaths>
</HttpCompress>
</DCWeb>
<!--the Js.axd and Css.axd must is enabled to allow JavaScript and CSS
Compression-->
<!--If you do not need to use this feature, you can delete this configuration section-->
<add verb= "*" Path= "Js.axd,css.axd"
Type= "Dc.web.httpcompress.compressionhandler,dc.web.httpcompress"/>
<!--the compression module must is enabled for the WebResource.axd.
Compressed-->
<add name= "Scriptmodule" type= "System.Web.Handlers.ScriptModule,
System.Web.Extensions, version=1.0.61025.0, Culture=neutral,
Publickeytoken=31bf3856ad364e35 "/>
<!--setting parameters to enable the compression module-->
<add name= "Httpcompressmodule"
Type= "DC. WEB.HTTPCOMPRESS.HTTPMODULE,DC. Web.httpcompress "/>
After the configuration, the compression module can work properly!
Tip: If the web.config is configured
<cachesettings cachefiles= "True" path= "cache"/>
Then the project must exist cache this directory, otherwise the words will be wrong, if the project does not want to add this directory, just want to delete this configuration section!
Second, the actual application of the performance test
Current 1/2 page
12 Next read the full text