---
title: "tomcat gzip功能启动web手机办公页面压缩效果比较"
author: "redhacker"
date: "2012-09-20T10:23:37Z"
tags: []
categories: ["移动开发"]
slug: "tomcat-gzip-web"
draft: false
lastmod: "2014-06-23T12:57:39Z"
id: 1682020
url: "https://redhacker.iteye.com/blog/1682020"
---

一、参考：
<http://blog.prosight.me/index.php/2009/06/91>
<http://blog.csdn.net/hbcui1984/article/details/5666327>
<http://hi.baidu.com/javacookies/item/04341eb97e059fa1eaba93c2>

二、确定自己项目的mediaType

通过firebug抓取，我自己项目的mediaType有如下类型：


> "text/html,text/javascript,application/xhtml+xml,text/xml,text/plain,application/javascript,application/json,text/css,image/gif,image/png,application/octet-stream" 
> 


三、确定tomcat server.xml里的配置参数

在server.xml里的Connector标记中加入如下属性


> //启动压缩
> compression="on"
> 
> //压缩支持的格式
> compressableMimeType="text/html,text/javascript,application/xhtml+xml,text/xml,text/plain,application/javascript,application/json,text/css,image/gif,image/png,application/octet-stream"
> 
> //对那些浏览器不进行压缩（建议该值不配置）
> noCompressionUserAgents="gozilla, traviata"
> 
> //文件应用压缩的最小值，即如果小于该值则不进行压缩，单位B（bit），2048代表2KB
> compressionMinSize="2048" 
> 

四、效果测试：

![](http://dl.iteye.com/upload/attachment/0074/0819/e7e4be29-b270-3ab4-9be6-f2db4f7cafc0.png)

![](http://dl.iteye.com/upload/attachment/0074/0821/996e4cb9-8554-316b-b1f4-da69bba5a728.png)

五、测试是否启动gzip的网站

<http://www.gidnetwork.com/tools/gzip-test.php>


<span style="color:gray">如果您觉得本文对您有益，请点击博文后的google广告，对作者表示支持，谢谢！</span>