---
title: "tomcat中使用gzip对html,xml,js,plain进行压缩"
author: "wanggp"
date: "2011-02-01T08:55:30Z"
tags: []
categories: ["编程语言"]
slug: "tomcat-gzip-html-xml-js-plain"
draft: false
lastmod: "2011-02-01T08:55:30Z"
id: 900531
url: "https://wanggp.iteye.com/blog/900531"
---

参考[http://tomcat.apache.org/tomcat-5.5-doc/config/http.html](http://tomcat.apache.org/tomcat-5.5-doc/config/http.html)

在server.xml中的connector元素中增加如下属性

               compression="on"  
               compressionMinSize="2048"  
               noCompressionUserAgents="gozilla, traviata"  
               compressableMimeType="text/html,text/xml,text/plain,text/javascript,application/x-javascript,application/javascript"

重启Tomcat即可，可以使用fiddler查看返回的类型是否为gzip

对pdf和image都不要使用gzip进行压缩，因为他们是已经压缩过了的（参考[http://developer.yahoo.com/performance/rules.html](http://developer.yahoo.com/performance/rules.html)）

 

本文来自CSDN博客，转载请标明出处：[http://blog.csdn.net/kingquake21/archive/2009/09/27/4601114.aspx](http://blog.csdn.net/kingquake21/archive/2009/09/27/4601114.aspx)