Because of these amounts of connections, downloading time is increased; content negotiation and the fact that normally there will be only two concurrent connections to the same host, produces an overhead that results in a long page loading time. For example, it is faster to serve a 8KB script file than eight of 1KB.
The goal for Jawr is to provide a system to easily map resources to bundles using a simple descriptor, and a tag library to import these bundles to JSP pages.
Using Jawr in only Servlet based web applications are easy. Jawr comes with a Servlet net.jawr.web.servlet.JawrServlet, where you define Jawr configuration file, and a workable mapping for js extensions. (http://jawr.java.net/docs/servlet.html).
But in case of Spring MVC web applications, things are bit complicated. Jawr provides a Spring controller, that acts the same manner as previous Servlet, but instead of using servlet-mapping tag you must create a SimpleUrlHandlerMapping.
In this post I will explain you how to create a Spring MVC jQuery web application integrated with Jawr. Let's start with a Spring MVC application that does not contain any references to Jawr.
JSP page contains definitions for all elements required by jQuery plus one custom script file (defining a() function).
and in servlet-context.xml static resources (Scripts and CSS) mapped correctly.
This web application contains four references to static resources, so load diagram looks like:
Let's start mapping resources. This is specified in jawr.properties file that should be present in root classpath:
Next step is changing JSP, so instead of having one reference for each file, only contains one reference to jawr.js.bundle.all.id value.
Jawr provides a tag library used to generate tags that import bundles to clients and these tags are <jawr:script/> and <jawr:style/>.
Unlike Servlet approach, web.xml don't have to be modified, Jawr provides a Spring controller that must be configured as you would do in Servlet approach.
Next step is configuring Spring Controller. Jawr site provides documentation about how to configure a Spring MVC with Jawr. The example provided uses old-school fashion configuration controllers using SimpleUrlHandlerMapping. But because I always use annotated controllers and I don't want to have some controllers defined with annotations and other ones in UrlMapping, in this post Jawr Spring Controller has been extended for being used with annotations.
For implementing Jawr Spring Controller with annotations I have only created an aggregation between annotated controller and Jawr controller. So class looks:
and the same approach for CSS is used but changing RequestMapping to /**/*.css and Qualifier to jawrCSSController.
Finally <resources> tag from servlet-context.xml should be changed to:
<resources mapping="/css/images/**" location="/css/images/" />
because now only images are required to be served as static resources.
With previous changes applied, load diagram looks like:
You can also speed up even more your response time using a cache strategy, but this topic is out of scope of this document.
I wish you have found this post useful, and now before using jQuery scripts, prepare your environment with Jawr so your application can be loaded even faster.
I hope you find this post useful.