|
example module definitions:
modules = { moduleOne { resource url: 'path/to/js/file1.js' resource url: 'path/to/js/file2.js' resource url: 'path/to/js/file3.js' } moduleTwo { resource url: 'path/to/js/file4.js' resource url: 'path/to/js/file5.js' } } For example, I'd like to preserve the order of these scripts as they're declared in the GSP (in other words: "external, inline, external): <r:require module="moduleOne" /> <r:script> // some js that depends on moduleOne and affects moduleTwo </r:script> <r:require module="moduleTwo" /> The default output is this (with all inline r:script scripts coming after all external r:require scripts) <script src="static/path/moduleOne.js"></script><script src="static/path/moduleTwo.js"></script><script> // some js that depends on moduleOne and affects moduleTwo // (too late to affect moduleTwo) </script> The desired output would be: <r:require module="moduleOne" /> <r:script> // some js that depends on moduleOne and affects moduleTwo // order preserved NS.someMethod(); </r:script> <r:require module="moduleTwo" /> One possible workaround is to do this: <script src="${staticResource(dir: 'path/to/js', file: 'file3.js')}"></script><script> NS.someMethod(); </script><script src="${staticResource(dir: 'path/to/js', file: 'file5.js')}"></script> The above workaround works since the resources plugin is smart enough to recognize that file3.js is part of the moduleOne module and file5 is part of the moduleTwo module. Admittedly this is an edge case and other options such JavaScript AMD loaders could solve the problem. But I'm curious to know if there's a way to get the resources plugin to preserve or force the mix-and-match (external, inline, external) order of the r:require and r:script scripts. Thanks! |
|
You can also use the 'defer' directive to manage some of the ordering
yourself, but I think the control you're looking for is more granular. On 28 July 2012 00:19, andyford <[hidden email]> wrote: > example module definitions: > > modules = { > moduleOne { > resource url: 'path/to/js/file1.js' > resource url: 'path/to/js/file2.js' > resource url: 'path/to/js/file3.js' > } > moduleTwo { > resource url: 'path/to/js/file4.js' > resource url: 'path/to/js/file5.js' > } > } > > For example, I'd like to preserve the order of these scripts as they're > declared in the GSP (in other words: "external, inline, external): > <r:require module="moduleOne" /> > <r:script> > // some js that depends on moduleOne and affects moduleTwo > </r:script> > <r:require module="moduleTwo" /> > > The default output is this (with all inline r:script scripts coming after > all external r:require scripts) > > > > > The desired output would be: > <r:require module="moduleOne" /> > <r:script> > // some js that depends on moduleOne and affects moduleTwo > // order preserved > NS.someMethod(); > </r:script> > <r:require module="moduleTwo" /> > > One possible workaround is to do this: > > > > > The above workaround works since the resources plugin is smart enough to > recognize that file3.js is part of the moduleOne module and file5 is part of > the moduleTwo module. > > Admittedly this is an edge case and other options such JavaScript AMD > loaders could solve the problem. But I'm curious to know if there's a way to > get the resources plugin to preserve or force the mix-and-match (external, > inline, external) order of the r:require and r:script scripts. > > Thanks! > > > > -- > View this message in context: http://grails.1312388.n4.nabble.com/resources-plugin-Is-there-a-way-to-preserve-the-order-of-scripts-loaded-via-r-require-and-r-script-tp4632358.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > -- ________________________________ ęś˝ . antony jones . http://www.enzy.org --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
