Do the project used extjs4.0 framework, but the introduction of js, css files too much and big, especially ext-all.js, 1.2 M, the page Initialization is very slow and consumes bandwidth, because the use of the server is tomecat, finally, we will use gzip with tomecat configuration to compress the request file. The configuration steps are as follows:
1: Find the server. xml file under the conf file of tomecat, open it, and find
<Connector port = "8080" protocol = "HTTP/1.1"
ConnectionTimeout = "20000"
RedirectPort = "8443" type = "regxph" text = "yourobjectname"/>
2: Add attributes to the tag.
Compression = "on"
CompressionMinSize = "2048"
NoCompressionUserAgents = "gozilla, traviata"
CompressableMimeType = "text/html, application/xml, application/javascript, text/css, application/json, image/png, image/gif, image/jpg"
Note: The value in compressableMimeType is the file that requires tomecat compression. For example, application/javascrip is used to compress the published js file. Other files can be compressed on the web in conf. found in xml, as shown in
<Mime-mapping>
<Extension> css </extension>
<Mime-type> text/css </mime-type>
</Mime-mapping>
Shows how to configure css compression.
Maybe we will be curious, ext-all.js is not already compressed JavaScript, has no comments and spaces, why can continue to compress? For example, gzip compression can be used to modify the variable name and define it with the least number of characters as much as possible. This can also greatly reduce the number of characters.
How can I check whether the compression takes effect? For example, use firedebug of firefox as follows:
Request before compression:
After compression:
Through comparison, we found that the size of js files and css files significantly changed.