On the surface, Jawr is a resource bundling library for Java web-apps with an incredibly confusing name (try saying “Put the Jawr JAR in the lib dir” a few times out loud…). The project website has this to say about it:
But why should I bundle my resources anyway?
First the CSS:
5 resources weighing in at 40k. Not terrible, but that’s a lot of requests for just the CSS. Every single one adds overhead that stands between the report and its intended viewer. Since this is a screenshot from my development environment, the timeline may be a bit misleading, but in this case loading these resources probably won’t take up enough time to be any real concern.
6 resources and 340k! Even on a fast connection this is going to take a few seconds to come down the wire. These requests are intentionally made after the rest of the page has loaded, but a good chunk of the functionality relies on these scripts; until they load the visitor is going to be staring at a sweet-looking UI without any real way to interact with it. Worse still, as the project grows so grows the resources; bundling just became important.
Jawr to the rescue
There are plenty of ways to manage the size of your resources:
- Concatenation, or smooshing all of your resources into a single massive file.
- Minification, aka “hope you weren’t planning to make any changes to that script”.
- Compression, which often means run-time decompression. I’m talking Packer, not GZip (which is awesome).
For the most part these are fantastic in a production environment, but while I don’t have the benefit of your own experience to draw upon, in my experience the only kind of project that isn’t constantly being reworked and redeployed is a dead one. While Jawr is one of many ways to achieve the best of both worlds &mdash& a clean development environment and compact production resources — I really appreciate how simple it is to configure and maintain.
Configuring the servlets
One thing to note is that every request for a bundle will be routed here. When debugging in your development environment, it’s best to flip the
jawr.debug.on property to
true. Jawr will then serve up all of the uncompressed resources that would have appeared in the bundle.
Adding Jawr to the JSPs
Jawr comes with a small taglib for use inside of an application’s JSP files. The
jwr:style tags will interpret Expression Language natively, and simply refer to a bundle definition within
jawr.properties before handling the request.
<@ taglib uri="http://jawr.net/tags" prefix="jwr" %>
With bundling enabled, the application sees a dramatic benefit.
CSS Just under 6k! It wasn’t huge before, but it’s certainly not causing any trouble now. In fact this same project is using sprites that come in larger than the CSS that drives them. Maybe something to investigate another time!
60k is certainly a reasonable size for some pretty large libraries, and represents an incredible more than 80% savings over the uncompressed example. Jawr does allow you to specify which minification method to use, and it’s certainly worthwhile to play around and see which options work best for your project. These figures came from a quick default integration, and I couldn’t be happier with the way things turned out.