Placement Of JS Resource Via <r:external />

北慕城南 提交于 2019-12-11 11:19:22

问题


I'm using the Resources plugin in Grails 2.0.1. The issue I'm having is getting a JavaScript resource specified using r:external to be placed after all of the other script previously declared using either r:require or r:external, all in the deferred disposition. Currently the resource specified using r:external it is being output in the location where the r:external tag is placed.

I have a layout file that contains an r:require tag to fetch some core resources:

<html>
<head>
    ...
    <r:require module="core" />
</head>
....
</html>

Then a GSP that includes another r:require tag followed by an r:external tag:

<head>
    ...
    <r:require module="forms" />
    <r:external dir="js" file="page-specific-resource.js" /> %{-- specifying disposition="defer" has no effect --}%
    ....
</head>
...

My expectation is each of the JavaScript resources I'm trying to include would be output in the deferred disposition with the core resources first, the forms resources next, and the page-specific resource last. The actual results are that the core and forms resources are output as expected in the deferred disposition, but the page-specific resource is output in head, where the r:external tag is placed (Specifying disposition="defer" seems to have no effect).

Is my expectation incorrect or is this a legitimate issue? Is there another way to specify page-specific resources (I'm trying avoid declaring these types of resources in the resource DSL) and have the positioned after all previously declared resources?


回答1:


As answered by Marc Palmer on the Grails User mailing list (http://grails.1312388.n4.nabble.com/Placement-Of-JS-Resource-Via-lt-r-external-gt-td4506074.html#none):

I'm afraid your expectation is incorrect.

r:external is just for rendering links where you invoke it.

You need to declare your dependencies, or put your r:external at the end of the page.

Declaring modules for "functional areas" of your app is profitable. It means you can also bundle them together if need be, or have fine grained control and the page no longer needs to be aware of that.



来源:https://stackoverflow.com/questions/9845513/placement-of-js-resource-via-rexternal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!