Javascript and CSS frameworks in Grails plugins

Posted by: on Apr 26, 2010 | One Comment

The Weceem CMS plugin for Grails uses the Blueprint CSS framework, jQuery and jQuery UI Javascript libraries. As the Grails plugin marketplace continues to mature, other plugins will have more polished user interfaces or reusable tags that require certain libraries.

This raises an ugly prospect: a new resource dependency problem. Only unlike java dependency problems this is worse as you end up with multiple copies of resources in your app, even if they are the same version because plugins will typically bundle the resources themselves. Your app may add some of these too and your site becomes slow to load or experiences failures related to clashing library versions.

There is however a staggeringly simple solution to this: lightweight Grails plugins that contain the resources.

Thanks to Grails’ automatic dependency resolution we (the grails community) can just create plugins to wrap up each such library and then we just make any apps or plugins that require them depend on them by installing the library plugin or adding it to the dependsOn clause of other plugins.

An important caveat here is that the library plugins need to use version numbers matching the version of the library they encapsulate. Then if you want jQuery 1.4.2 you depend on/install grails-jquery version 1.4.2 or higher. The grails-jquery plugin authors have already done this.

These plugins should implement a simple tag called “resources” in an appropriate namespace e.g. or .

I strongly believe that such plugins should NOT include other tags or more heavyweight tags wrapping up library features – do that in another plugin e.g. “grails-jquery-tools”.

This approach does provide new challenges for optimizing static content – minifying JS and CSS and including only required modules from a larger library remains awkward as it is today with non-dependency solutions.

Ultimately I think we need smarter solutions than those currently in use to solve this. I have some ideas forming…

1 Comment

  1. Kim
    April 27, 2010

    I’ve been thinking about this as well. Not only do you need the correct version of the appropriate Javascript libraries you also have to include them in the appropriate order. Another thing is that you don’t want to include the same file twice. And as you say, ultimately you want to bundle related files together to reduce http requests.

    A couple of weeks ago I played around with a system building on plugins with manifests of their client side files, and their dependencies. It turned out to be to a complex beast so I gave it up.

    It would be nice to have a Grails wide system for doing these things built into Grails or as a Grails plugin. At my job we have a quite nice plugin that solved at least some of these problems for css which I hope to be able to release to the Grails community soon.