我应该将 javascript 库放在 Grails 应用程序中的什么位置? [英] Where should I put javascript libraries in a Grails app?

查看:17
本文介绍了我应该将 javascript 库放在 Grails 应用程序中的什么位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个自己的 Javascript 库,可以很好地美化我的 HTML 页面,我想将它们包含在我的 gsp 页面中,尤其是我的应用程序的登录页面.我试过把它们放在 views 文件夹和 web-app/js$APP_HOME/scripts 但是当我加载我的 index.gsp 脚本不要出现.

I have a couple of Javascript libraries of my own that do some nice prettyfying of my HTML pages and I want to include them in my gsp pages, particularly the landing page of my app. I have tried putting them in views folder and web-app/js and $APP_HOME/scripts but when I load my index.gsp the scripts don't show up.

我也在我的代码中尝试了各种替代方案,但没有一个有效......

I have also tried a variety of alternatives in my code none of which work...

<script src="mylib.js" type="text/javascript"></script>
<script src="js/mylib.js" type="text/javascript"></script>
<script src="scripts/mylib.js" type="text/javascript"></script>

我确信有一种聪明的 grails 方法可以即时执行此操作,但我真的只想要一个位置,可以在其中放置一些可以在我的应用程序中使用的样板 JavaScript 代码.考虑到约定优于配置,预期的做法是什么?

I'm sure there is a clever grails way of doing this on the fly, but I really just want a location where I can place some boilerplate JavaScript code that I can use in my app. With convention over configuration in mind, what is the expected practice?

推荐答案

使用您的 JS 文件:web-app/js/myLib.js,放入 <g:javascript library="myLib"/> 在您的布局中,我认为应该是您需要的.

With your JS file at: web-app/js/myLib.js, putting <g:javascript library="myLib" /> in your layout should I think be what you need.

这篇关于我应该将 javascript 库放在 Grails 应用程序中的什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆