g:include VS multiple asset:javascript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

g:include VS multiple asset:javascript

Scott Ingram
I have numerous widgetFoo.gsp files that declare all the JS and CSS dependencies required to produce a fully functional FOO widget.  This allows me to go directly to any given http://myapp/controllerBar/widgetFoo all by itself, or, to include widgetFoo and its siblings into a workbench.gsp that leverages g:include on widgetFoo, widgetBar, widgetEtc.

widgetFoo.gsp : <r:require modules="widget-foo"/> which declares (resource url:'widget/foo.js') and (dependsOn 'js-core')
widgetBar.gsp : <r:require modules="widget-bar"/> which declares (resource url:'widget/bar.js') and ALSO (dependsOn 'js-core')
workbench.gsp: says g:include widgetFoo and g:include widgetBar

In Grails 2 and the Resources Plugin, this worked great!

In Grails 3 and the Asset Pipeline, not so much...

widgetFoo.gsp :  <asset:javascript src="/widget/foo.js"/>  which declares //= require manifest-core-js
widgetBar.gsp :  <asset:javascript src="/widget/bar.js"/>  which ALSO declares //= require manifest-core-js
workbench.gsp: says g:include widgetFoo and g:include widgetBar

which then generates a page which includes multiple copies of the complete dependency tree.  Mo widgets, mo problems.

Would this be considered a bug in Asset Pipeline?

I tried to workaround this behavior by placing the  <asset> tags in the <HEAD> of the widgetX.gsp files and having workbench.gsp use <g:applyLayout name="body-only">  where layouts/body-only.gsp contained nothing but a <g:layoutBody>tag, but, that failed too, with identical results as before.  I guess and <asset> tag isn't treated as an element of its enclosing HTML block. 

I've concluded that I must remove the //= require manifest-core-js directives from widget/foo.js and widget/etc.js files where they belongs and move them into a layout/widget.gsp instead.  This will allow me to bypass this problem by having my workbench.gsp do <g:applyLayout name="i-pretend-to-have-no-dependencies"><g:include widget/foo.js>.  Even though this prunes the dependency tree incorrectly (widget/foo.js now lies and claims that it is free of any dependencies), opening up the possibility of assets being included in the wrong order, it works out fine in the end because Asset Pipeline continues bad behavior by inserting the <link> at the position of  the <asset:javascript src="/widget/foo.js"/>  tag.  Yay?

Is there a better solution?


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4112f866-42b2-49bb-8f32-9de3465e395b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.