1 Overview - Reference Documentation
Authors: Marc Palmer (marc@grailsrocks.com), Luke Daley (ld@ldaley.com), Peter N. Steinmetz (ndoc3@steinmetz.org)
Version: 1.2.14
Table of Contents
1 Overview
This plugin provides the Resources framework for Grails.The issues that the Resources framework tackles are:- Web application performance tuning is difficult
- Correct load order for resources that depend on others
- Deferring inclusion of JavaScript to the end of the document
- The need for a standard way to for Grails plugins to expose static resources
- The need for an extensible processing chain to optimize resources
- Preventing inclusion of the same resource multiple times
- The need for identical behaviour in development and production
1.1 Quick Start
To demonstrate the power of the framework, here's a quick demonstration of usage with the jQuery, jQuery-Ui and Blueprint plugins which exposes resource modules.1.1.1 Make sure jQuery plugin is installed
For Grails 1.4, it is installed by default. For older versions:grails install-plugin jquery*
1.1.2 Install jQuery UI and Blueprint plugins
Just run:grails install-plugin jquery-ui grails install-plugin blueprint
1.1.3 Edit your Sitemesh layout
You need to add the layoutResources tag twice to your page, for the <head> resources and end-of-body resources.Your grails-app/views/layouts/main.gsp:<html> <head> <g:layoutTitle/> <r:layoutResources/> </head> <body> <g:layoutBody/> <r:layoutResources/> </body> </html>
1.1.4 Edit your GSP page to include jQuery
All you have to do here is add the require to your GSP page. Anywhere will do, but in <head> makes sense, and add a bit of code:<html> <head> <meta name="layout" content="main"/> <r:require modules="jquery-ui, blueprint"/> <r:script> $(function() { $('#form').dialog('open'); }); </r:script> </head> <body> <div id="form"> Hello World </div> </body> </html>
1.1.5 View the page source
When you run this and request the GSP page, you should view the source and look at what is happening in the page. Use Safari or Chrome resource inspector to see what files were requested and when.You should have a page that is rendered with the Blueprint CSS framework, pulling in both jQuery and jQuery-UI, with jQuery-UI JS deferred to the end of the page, jQuery loaded in the head, and the "document ready" JS code fragment to set up the page is rendered right at the end of the body after jQuery UI has loaded.All with almost zero effort!1.1.6 Now optimize your application
Installing the "cached-resources" and "zipped-resources" plugins and running your app again, you will then find that your resources are cached in the browser "eternally" and transferred with zip encoding.Simply run these commands:grails install-plugin zipped-resources grails install-plugin cached-resources