DukeScript,为什么使用@JavaScriptResource而不是使用< script>导入js资源? [英] DukeScript, why using @JavaScriptResource rather than importing a js resource with <script>?
问题描述
定义一个类JQuery并将JavaScript库添加到您的项目中. 现在,您可以使用@JavaScriptResource引用它.这就是你 在DukeScript中管理JavaScript库
Define a class JQuery and add the JavaScript-library to your project. Now you can reference it using @JavaScriptResource. This is how you manage JavaScript libraries in DukeScript
与在html页面内包含带有<script>
标记的javascript文件有什么不同吗?
我已经尝试过这两种方法,但看不出为什么使用批注@JavaScriptResouce会有所不同.
Is that any different from including a javascript file with the <script>
tag inside an html page?
I've tried both and couldn't see why using the annotation @JavaScriptResouce would be any different.
推荐答案
@JavaScriptRessource的主要思想是使用它来通过javascript库定义自己的Java API,例如淘汰的API.
The main idea of @JavaScriptRessource is to use it for defining your own Java API over a javascript library, e.g. the API for knockout.
使用脚本"将是用户的责任,以提供正确的版本.使用@ JSR,API的用户不必了解所需的JS文件.相反,您使用API交付了正确的版本. API的用户只需要处理Java.
With "script" it would be the users responsibility to provide the correct version. With @JSR the user of the API doesn't have to know anything about the required JS-file. Instead you deliver the correct version with the API. The user of the API only has to deal with Java.
如果您仅将JS用于样式和布局(例如,引导程序等),则只需通过"script"标记添加即可.
If you use JS only for styling&layout (e.g. bootstrap, etc.) it's fine to just add it via "script" tag.
这篇关于DukeScript,为什么使用@JavaScriptResource而不是使用< script>导入js资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!