Skip navigation
2013

Minification is often considered to be a best practice for improving the performance of web applications since it helps to reduce page loading time. The wro4j plugin is one tool that can be used to minify JavaScript and CSS files at build-time or at run-time.

Manually configuring minification using wro4j

If you want to set up JavaScript and CSS minification at build-time for a web application that will be deployed on JBoss AS 7 or EAP 6 on OpenShift, you can do the following:

 

  1. Add a "minify" profile that configures the wro4j plugin to your pom.xml.
  2. Add a wro.properties file to src/main/webapp/WEB-INF/.
  3. Add a wro.xml file to src/main/webapp/WEB-INF/.
  4. Make sure the minified versions of your JavaScript and CSS files are referenced in your web application code.
  5. Override OpenShift's default maven arguments by setting MAVEN_ARGS in .openshift/action_hooks/pre_build_{jbossas-7,jbosseap} as follows:
MAVEN_ARGS="clean package -Popenshift,minify -DskipTests"

 

After completing these steps, the next time you use the OpenShift infrastructure to build your web application (e.g., after a git push), wro4j will be used to minify your files. Want to see an example? Take a look at the kitchensink-html5-mobile quickstart for an example of how to configure the wro4j plugin in pom.xml and for a sample wro.properties file and a sample wro.xml file.

Automatic wro4j configuration?

Although the minification configuration described above isn't too painful, it has to be repeated for each web application that's created. Since it's generally considered good practice to use minification, there could be value in having the OpenShift AS 7/EAP 6 cartridges do some of this configuration automatically. It's one way to make it easier for users to optimize their web applications. Note that when an application is created using the AS 7 or EAP 6 OpenShift cartridge, a default pom.xml file and a default maven src structure are created. The cartridge could potentially configure wro4j for the user by doing some or all of the following:

 

  • Adding a "minify" profile to the default pom.xml.
  • Adding a sample wro.properties and a sample wro.xml file to the default src/main/webapp/WEB-INF directory.
  • Adding the "minify" profile to the default maven arguments used to build the application. Alternatively, instead of enabling minification by default, a user could be required to specify that they want to use the "minify" profile by overriding OpenShift's default maven arguments via the pre_build_{jbossas-7,jbosseap} action hook.

 

Any thoughts on this?

Filter Blog

By date:
By tag: