简体   繁体   English

Grails application.js没有执行

[英]Grails application.js not executing

I have a Grails (2.3.6) app, and have included the asset-pipeline plugin as a dependency. 我有一个Grails(2.3.6)应用程序,并且包含了asset-pipeline插件作为依赖项。 In my Config.groovy : 在我的Config.groovy

plugins {
    // Lots of other stuff

    compile ":asset-pipeline:1.8.7"
}

In myapp/web-app/js/application.js (generated for me by Grails), I have only the following single line of code: myapp/web-app/js/application.js (由Grails为我生成)中,我只有以下一行代码:

alert("Hello!");

Then in my grails-app/views/index.gsp : 然后在我的grails-app/views/index.gsp

<html>
    <head>
        <asset:javascript src="application.js" />
    </head>
    <body>
        ...
    </body>
</html>

When I do a grails run-app , I don't see my JS alert(...) statement fire. 当我执行grails run-app ,我看不到我的JS alert(...)语句触发。 Have I positioned my application.js file incorrectly? 我的application.js文件放置不正确吗? Have I configured the asset-pipeline plugin incorrectly? 我是否配置了asset-pipeline插件错误? Anything else I'm doing wrong? 我做错了什么吗? I just want to see my alert box! 我只想查看我的警报框!

Additionally, following the " put CSS at the top, and JS at the bottom " convention, I was wondering if anyone could chime in as to how I could reposition the application.js to appear at the bottom of the <body/> tag. 另外,遵循“ 将CSS放在顶部,而JS放在底部 ”的约定,我想知道是否有人可以将我重新放置application.js使其显示在<body/>标记的底部。 My understanding was that asset-pipeline assets only work inside of <head/> . 我的理解是, asset-pipeline资产仅在<head/>内部起作用。

Your static files go in grails-app/assets/. 您的静态文件位于grails-app / assets /中。 See organization for the details. 有关详细信息,请参见组织

According to the documentation for the asset-pipeline plugin your assets should be under the grails-app/assets/ directory structure. 根据资产管道插件的文档 ,您的资产应位于grails-app / assets /目录结构下。 Each type of asset is under a sub folder as follows: 每种资产都在子文件夹下,如下所示:

grails-app/assets/javascripts
grails-app/assets/images
grails-app/assets/stylesheets

Move your application.js into the javascripts directory for asset-pipeline to pick it up. 将您的application.js移到javascripts目录中,以资产管道进行拾取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM