问题描述
我正在使用Grails 2.0.1中的Resources插件。我遇到的问题是,将使用r:external指定的JavaScript资源放置在之前使用r:require或r:external声明的所有其他脚本之后,这些脚本全部位于延迟处置中。目前使用r:external指定的资源正在输出到r:external标签所在的位置。
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.
我有一个布局文件,其中包含r:require标签来获取一些核心资源:
I have a layout file that contains an r:require tag to fetch some core resources:
<html>
<head>
...
<r:require module="core" />
</head>
....
</html>
然后包含另一个r:require标签后跟r:external标签的GSP:
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>
...
我的期望是我试图包含的每个JavaScript资源将首先在核心资源,表单资源和页面特定资源的延迟配置中输出。实际结果是,核心表单和表单资源按照预期在延迟处置中输出,但页面特定的资源在头部输出,r:外部标记放置在该处(指定处置=延迟似乎没有效果)。
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).
我的期望是不正确的还是这是一个合理的问题?是否有另一种方式来指定页面特定的资源(我试图避免在资源DSL中声明这些类型的资源),并具有所有先前声明的资源?
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?
推荐答案
正如Marc Palmer在Grails用户邮件列表中所回答的():
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):
r:external仅用于渲染引用它的链接。
r:external is just for rendering links where you invoke it.
你需要声明你的依赖关系,或者把你的r :外部在页面的
结尾。
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.
这篇关于通过< r:external />放置JS资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!