JavaWeb开发分享:WRO

52 篇文章 0 订阅

WRO是为了提高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 here. They have created a tool called YSlow: 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

<filter>
  <filter-name>WebResourceOptimizer</filter-name>
  <filter-class>
    ro.isdc.wro.http.WroFilter
  </filter-class>
</filter>
<filter-mapping>
  <filter-name>WebResourceOptimizer</filter-name>
  <url-pattern>/wro/*</url-pattern>
</filter-mapping>


WRO configuration in maven pom.xml

        </dependency>
        <dependency>
            <groupId>ro.isdc.wro4j</groupId>
            <artifactId>wro4j-core</artifactId>
        </dependency>

WRO properties and xml

debug=false
managerFactoryClassName=ro.isdc.wro.manager.factory.ConfigurableWroManagerFactory
preProcessors=cssUrlRewriting,semicolonAppender,cssMinJawr
gzipResources=false
encoding=UTF-8
ignoreMissingResources=false
postProcessors=cssVariables,jsMin
uriLocators=servletContext,uri,classpath

more details: https://code.google.com/p/wro4j/wiki/ResourceTypes https://code.google.com/p/wro4j/wiki/AvailableProcessors

WRO xml file

<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns="http://www.isdc.ro/wro">
    <group name="system-scripts">
        <js>classpath:META-INF/resources/webjars/jquery/1.9.0/jquery.min.js</js>
        <js>classpath:META-INF/resources/webjars/bootstrap/3.0.2/js/bootstrap.min.js</js>
        <js>classpath:META-INF/resources/webjars/jquery-cookie/1.3.1/jquery.cookie.js</js>
        <js>/scripts/script.js</js>
    </group>
</groups>

最后在jsp文件中把要引用的javascript链接改成如下:

<span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="html" style="font-size: 13.3333339691162px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">  <script type="text/javascript" src="/wro/system-scripts.js"></script></span>

 

Note: 

1. css文件类似,把css group起来,然后引入group.css

2. wro properties文件可以不用自己写,在maven中有好插件: wro4j-maven-plugin

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值