Search code examples
jquerydukescript

DukeScript, why using @JavaScriptResource rather than importing a js resource with <script>?


Quote from Using the Knockout API

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

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.


Solution

  • 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.

    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.

    If you use JS only for styling&layout (e.g. bootstrap, etc.) it's fine to just add it via "script" tag.