本文共 2060 字,大约阅读时间需要 6 分钟。
是为了提高Java Web前端的性能而出现的技术,简单来说它的功能就是压缩(processor)和组合文件(group),减少文件传输次数和大小。
There are countless articles related to web performance. The most comprehensive one is performed by researchers from Yahoo. They have identified a number of best practices for making web pages fast. You can find the details . They have created a tool called : which analyzes web pages and tells you why they're slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with the popular Firebug web development tool.
The aim of wro4j project is to help application developed on java platform to address a couple of those problems described by Yahoo research. More, exactly it is about "Minimize HTTP Requests" and "Gzip Components".
为了使用WRO,需要在web.xml加入filter,在web应用中加入wro4j-core.jar,在web-int文件夹下面加入wro配置信息。WRO configuration in web.xml
WebResourceOptimizer ro.isdc.wro.http.WroFilter WebResourceOptimizer /wro/*
WRO configuration in maven pom.xml
ro.isdc.wro4j wro4j-core
WRO properties and xml
debug=falsemanagerFactoryClassName=ro.isdc.wro.manager.factory.ConfigurableWroManagerFactorypreProcessors=cssUrlRewriting,semicolonAppender,cssMinJawrgzipResources=falseencoding=UTF-8ignoreMissingResources=falsepostProcessors=cssVariables,jsMinuriLocators=servletContext,uri,classpath
more details: https://code.google.com/p/wro4j/wiki/ResourceTypes https://code.google.com/p/wro4j/wiki/AvailableProcessors
WRO xml file
最后在jsp文件中把要引用的javascript链接改成如下:classpath:META-INF/resources/webjars/jquery/1.9.0/jquery.min.js classpath:META-INF/resources/webjars/bootstrap/3.0.2/js/bootstrap.min.js classpath:META-INF/resources/webjars/jquery-cookie/1.3.1/jquery.cookie.js /scripts/script.js
Note:
1. css文件类似,把css group起来,然后引入group.css
2. wro properties文件可以不用自己写,在maven中有好插件: wro4j-maven-plugin转载地址:http://tbtmb.baihongyu.com/