I added the resources plug-in in a grails 1.3.7 application and everything works fine except javascript that is loaded asynchronously.
So if I have a template that conta
A better approach would be to have a dedicated layout for your AJAX responses:
<g:layoutBody/>
<r:layoutResources disposition="defer"/>
If you're using Grails 2.0, you can specify the layout in the render method (render template: "...", layout: "ajax"
). Otherwise, use layout by convention.
A better option I think is to not use r:script in your template fragment. Just use normal script tag. You are not getting any benefit from Resources inside these fragments if you don't need the layoutResources stuff.
Sometimes the classic way is the best.
I always go with Peter Ledbrook response, but instead of using a layout, I use a template and I automate what to render in the main layout. My main.gsp looks like the following:
<!DOCTYPE html>
<g:if test="${request.xhr}">
<g:render template="/layouts/content" />
</g:if>
<g:else>
<html>
... <!-- Main layout stuff: application resources, logo, main menu, etc -->
<div id="content"> <!-- Somewhere in the body -->
<g:render template="/layouts/content" />
</div>
</html>
</g:else>
Then, the _content.gsp template looks like:
<g:layoutBody />
<r:layoutResources disposition="defer"/>
<!-- Ajaxify your relative links with the framework of your choice -->
That way, I can automatically ajaxify all relative links and forms and no action is required in the controller (no different responses), since the ajax response always goes inside the content div.