Intro
Wro4j is a free and Open Source Java project which will help you to improve your web application page loading time. It can help you to keep your static resources (js & css) well organized, merge & minify them at run-time (using a simple filter) or build-time (using maven plugin or a command line tool) and has a dozen of other features you may find useful when dealing with web resources.The main target of wro4j framework is help to speed up web applications to be optimized by implementing a couple of recommended performance rules.
Starting with wro4j-1.3.4 release, it is not limited anymore to java development environment. If, for instance, you are developing a js framework with many small modules (ex: jquery, yui, mootools, etc) or if you are working on the client-side of a large web project, then wro4j can help you to easily organize all your static resources (css/js) and build them (merge and minimize) using a simple command line tool. The only prerequisite is to install jdk-1.6 on your machine.
This post will focus on description of the wro4j command line tool.Target audience: this post may be interesting not only for java developers, but also for web developers (using any kind of technology) and css/javascript framework creators.
Getting Started
Let's make it practical. We'll show how wro4j can help building the jquery tools project.Currently, it uses ant build script (build.xml) to describe how the js resources are merged and minimized. Also it supports google closure compiler only. Switching to another compressor is not supported. Using an ant script can be a good solution for many similar projects, but it also can be quite complex. Having a verbose and complex script is very hard to understand and maintain. Isn't there a simpler solution?
Installation Steps
With new wro4j command line tool, you can achieve the same results with minimum effort. All you have to do, is to follow the following steps:- Add wro4j-runner-1.3.4-jar-with-dependencies.jar. In our case, we add it to the lib folder (just where other jar files resides). The default relative context path depends on the location of the jar (this can be changed with an argument we'll get back to this later).
- Create wro.xml file and add it in the same folder where the jar is located. . This file describes how you want your resources to be merged and the resources location. For more details about wro.xml, visit this page. Here is an example:
/jquery-1.4.2.js /../src/**.js - Run the following in your console:
java -jar wro4j-runner-1.3.4-jar-with-dependencies.jar
As a result, a new folder (called 'wro') will be created. It will have one file: all.js containing a merged content of all js files from ui folder (as described in wro.xml).
Minimization (compression) configuration
Of course, it would be nice to have the all.js file compressed. In order to do that, make a small change to the console script:java -jar wro4j-runner-1.3.4-jar-with-dependencies.jar -mAdding -m attribute, inform the wro4j runner to minimize the scripts. By default, it uses JSMin processor for js compression. You can easily switch this compressor with other, here is an example:
java -jar wro4j-runner-1.3.4-jar-with-dependencies.jar -m -c uglifyJsThis will inform wro4j runner to use UglifyJs compressor instead. Similarly, you can use other compressor.
You don't have to worry when invoking the wro4j-runner with wrong arguments, it will inform you about the cause of the problem and in some cases can suggest possible solutions. Also, when everything is ok, you will see in command line the details about processing and total duration of the operation.
Supported Compressors
Currently wro4j-runner support the following js compressors:- jsMin - For JsMin compressor. This one is used by default if you don't specify any.
- uglifyJs - For UglifyJs compressor
- beautifyJs - Exactly the opposite of the uglifyJs, it does what it says - makes compressed code readable.
- googleClosureSimple - For Google Closure Compiler with simple optimization
- googleClosureAdvanced - For Google Closure Compiler with advanced optimization
- yuiJsMin - For YUI compressor with no munge
- yuiJsMinAdvanced - For YUI compressor with munge
- packerJs - Uses Dean Edwards Packer compressor (version 3.1)
- dojoShrinksafe - Uses Dojo Shrinksafe compressor.
You can easily switch between any of the preferred compressors, depending on your tastes or preferences. Maybe for some projects one compressor suites better than other. The nice part is that wro4j can support any possible existing javascript compressors. For more details visit wro4j project home page.
Wro4j runner arguments
Here you'll find all the arguments supported by wro4j runner tool.- -m or --minimize - Turns on the minimization by applying the default or specified compressor
- -c or --compressor - Name of the compressor to use. The complete list of supported compressors was described earlier.
- -i or --ignoreMissingResources - This is useful when you want the runner to do its job even when you specify an invalid resource in your wro.xml. By default missing resources are not ignored.
- --targetGroups ${GROUPS} - Comma separated list of groups (defined in wro.xml) to process. If you don't specify this argument, all existing groups will be processed and for each of them will be created a file.
- --destinationFolder ${PATH} - The folder where the target groups will be generated. By default it will create a folder called wro
- --wroFile ${PATH} - location of the wro.xml file. By default runner will search it in the current folder.
- --contextFolder ${PATH} - folder used as a root of the context relative resources (or where to search when you have a resource starting with / character). By default this is the current folder.
Summary
Starting with wro4j-1.3.4 release, you can easily maintain, merge and minimize client-side resources (css & js) with wro4j-runner command line tool. By following 3 simple steps, you can compress your static resources into a single compressed file, using one of 8 supported javascript compressor. This tool is easily customizable, flexible and can help you simplify the way you are building your client-side project.Resources
- Wro4j project home
- Wro4j github homepage
- Jquery tools project page - used as an example for this post
- Jquery tools using wro4j runner example
Wow, Thank you SOOOOO much!! you just saved me from having to reformat my entire hard disk :) System Optimization
ReplyDeleteGreat engaging information. Thank you for sharing. I found this post engaging and meaningful, which has added value to my understanding. Keep sharing good information. Thanks
ReplyDeleteAndroid app development
iOS App Development
Freelance software developer
ReplyDeleteHi, Very nice article. I hope you will publish again such type of post. Thank you!
Corporate gifts ideas | Corporate gifts
Corporate gifts singapore | Corporate gifts in singapore
Promotional gifts singapore | Corporate gifts wholesale Singapore
leather corporate gifts singapore | t shirts supplier singapore
thumb drive supplier singapore | business card holder singapore
corporate gifts supplier | customized corporate gifts singapore
corporate gifts supplier singapore
Thanks for sharing amazing engaging information. This has certainly added value to my knowledge. Please keep sharing such information in future as well.
ReplyDeletehiring virtual assistants
freelance website developer
Woah! I just spend 30 mins reading all of your recent posts. They were amazing and it was fun reading articles. Thanks for the excellent peice of content and sharing it with us, I hope you will keep posting such articles. Have a look on this usefull website too - Funny Things To Say and Get Rid of Boredom
ReplyDeleteThanks for sharing this blog its very helpful to implement in our work
ReplyDeleteFrench Classes in Chennai | French Institute in Chennai
Casino at Charles Town Races - Mapyro
ReplyDeleteThis casino 원주 출장안마 is located in Charles Town, Missouri 안양 출장샵 and is part 경산 출장마사지 of 전주 출장안마 the MGM National Forest Conservation District. The 대전광역 출장안마 casino is a gaming, entertainment,
Great article on creating a simple client-side build system with the wro4j command line tool! Your step-by-step explanation makes it easy to understand how to set up and utilize wro4j effectively. I especially appreciated the practical examples you provided; they really clarify how to manage resources efficiently. It would be interesting to see some performance benchmarks comparing wro4j with other build tools. Overall, this is a fantastic resource for developers looking to streamline their client-side build processes!
ReplyDeleteDigital Marketing Training In Ameerpet
a lightweight and efficient command-line tool that simplifies the process of building and managing client-side resources like CSS and JavaScript. With Wro4j, you can easily concatenate, minify, and optimize your assets, making it perfect for developers looking to streamline their front-end build processes without the overhead of more complex build systems. It's a great choice for projects that require performance improvements with minimal configuration.
ReplyDeleteDigital Marketing Training In Ameerpet