1

in my grails app, I'm using the awesome resource plugin which wires all the dependencies. When I'm doing the ajax calls I always use <r:layoutResources disposition="defer"/> in order to render all scripts <r:script>... and other dependencies property.

The problem is if I use <r:require module="myModule"/> and the module specify a JS file which was not loaded before (when the page was not loaded). After the AJAX call the JS file is not loaded, what is more or less expected because all JS file should be loaded when the page is rendered.

My question is how to solve it properly? Should I put my r:require to the gsp which is rendered during the first request? Or are there any plans to make the r:require deal with "external" JS files when AJAX?

Thanks, Mateo

1 Answer 1

1

Create a layout ajaxInternal.gsp and put in something like:

<r:require module="gaScript" />
<r:layoutResources />
<g:layoutBody />
<r:layoutResources disposition="defer" />

And in your ajax action of controller render this:

render(template:"aTemplateIfRequired", model:[yourModel],layout:'ajaxInternalContentBox')

So all your js will work properly and all your modules also.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.