extjs desktop js和css文件压缩

来源:互联网 发布:nginx 多站点 编辑:程序博客网 时间:2024/05/18 15:52

[gzip]使用tk-filters压缩Web页面资源

目的:压缩资源文件,减少流量,减少页面加载时间

1 首先,下载tk-filters-1.0.1.zip

2 解压这个tk-filters-1.0.1.zip压缩文件 ;

3 将解压后的文件tk-filters.jar放在项目的WEB-INF/lib/下

4 配置tk-filters.properties文件,注释非常明确,不再赘述,修改完后放在classpath及src下

## This properties file controls the behavior of the various# filters available in the Tacit Knowledge filters package.## Each filter has its own set of configuration directives,# prefixed with the filter name, that controls that specific# filter's behavior##############################################################                         ClusterCheck############################################################# A frequent problem when clustering is that applications use the session# in a non-clusterable way, so The "ClusterCheckFilter" instruments the # application server's sessions with checks to see if this is a problem.ClusterCheckFilter.Enabled=false# Its possible to check for modifications to session objects after# they have been set in to the session. This is a problem for sessions# that are replicated in a copy-on-write fashionClusterCheckFilter.UnsetModificationsCheck=false# Its possible to check serialized size to ensure high performance clusteringClusterCheckFilter.ByteSizeCheck=false# Aggregate size is important for containers that serialize the whole session# every time. An example would be a database-backed session store.# An aggregate size limit will also cap the maximum RAM used by sessions,# allowing you to quantify the RAM necessary for peak loads.ClusterCheckFilter.AggregateByteSizeLimit=30720# Attribute size is important because each time an attribute is put in a# session, it has to be serialized and persisted to a cluster peer, or# to a database (depending on clustering implementations). #Thus, very large# session attributes will be a performance problem.ClusterCheckFilter.AttributeByteSizeLimit=20480# ClusterCheck errors can return a 500 error to the client# in order to have "fail-fast" behavior, if this is turned on.# This is good for test machines, but is usually too aggressive for production.ClusterCheckFilter.ClientError=false###########################################################################################################################                          GZIPFilter############################################################## A performance boost can be achieved by sending data from the application# server to the client using the Gzip encoding. This incurs a small CPU# cost to gain a large network benefit. The GZIPFilter, when enabled, # transparently Gzip encodes all data after it leaves the application,# but before its transmitted to the client.# WARNING: GZIPFilter is currently not recommended for production use.#          It does not send all data under certain conditions.GZIPFilter.Enabled=true# Its possible for the GZIPFilter to log statistics about the compression# ratios and byte savings it is achieving. This turns that on or off.GZIPFilter.LogStats=false##############################################################                          CacheFilter############################################################## A server can send expiration headers to the client, enabling the client # to confidently cache certain pieces of static content. This eliminates # unnecessary conditional GETs from the client to validate the freshness of# content. If the application is on a server that doesn't do that, this# filter can be enabled and mapped to static content (images, javascript,# css files, etc), potentially reducing network traffic a great deal.CacheFilter.Enabled=true# This is the number of minutes the client will wait before verifying the# freshness of a piece of content.CacheFilter.ExpirationMinutes=15#############################################################

5 修改web.xml文件

<!--GZIPFilter压缩定义 设置此项时tk-filters.properties的                GZIPFilter.Enabled=true才可用--><filter><filter-name>GZIPFilter</filter-name><filter-class>com.tacitknowledge.filters.                 gzipfilter.GZIPFilter</filter-class></filter><!-- GZIPFilter 设置自己想要压缩的文件类型--><filter-mapping><filter-name>GZIPFilter</filter-name><url-pattern>*.js</url-pattern></filter-mapping><!--<filter-mapping> <filter-name>GZIPFilter</filter-name><url-pattern>*.jsp</url-pattern> </filter-mapping>--><!--CacheFilter缓存定义                 设置此项时tk-filters.properties的CacheFilte                 r.Enabled=true才可用--><filter><filter-name>CacheFilter</filter-name><filter-class>com.tacitknowledge.filters.cache                     .CacheHeaderFilter               </filter-class></filter><!-- CacheFilter 设置自己想要缓存的文件类型--><filter-mapping><filter-name>CacheFilter</filter-name><url-pattern>*.gif</url-pattern></filter-mapping><filter-mapping><filter-name>CacheFilter</filter-name><url-pattern>*.jpg</url-pattern></filter-mapping><filter-mapping><filter-name>CacheFilter</filter-name><url-pattern>*.png</url-pattern></filter-mapping><!--<filter-mapping><filter-name>CacheFilter</filter-name><url-pattern>*.js</url-pattern></filter-mapping><filter-mapping><filter-name>CacheFilter</filter-name><url-pattern>*.css</url-pattern></filter-mapping>

6 测试

测试使用FireFox,以及FireBug。ext-all-debug.js为1.3MB。压缩后得到的大小仅为272K,压缩率达到了79%。整个desktop页面1.6M,压缩后为349.6KB,压缩率为78.64%。

原创粉丝点击