Dynamic JavaScript loader for Vaadin - Vaadin Add-on Directory
Dynamic JavaScript loader for Vaadin using classpath or CDN.The Vaadin Dynamic JavaScript Loader unifies the import of JavaScript libraries from the Java classpath, web resources, and external URLs. It also supports integration with cloud services like [cdnjs.com](https://cdnjs.com/) and [unpkg.com](https://unpkg.com/) in Vaadin applications. It complements the built-in JavaScript and Stylesheet annotations by providing some useful features:
- **Library Bookkeeping**: Ensures a library is loaded only once per UI and checks the version.
- **Fully Dynamic Loading**: Enables runtime configuration and loading for greater flexibility.
- **Template-Based URL Syntax**: Allows atomic loading of multiple files or resources from a single library.
- **Load Script from Class path**: Unlike the built-in `@JavaScript`, you can also load scripts from Java resources and classpath.
- **Component Subclassing**: Due to its dynamic nature, Java component subclasses can modify and override loading behavior, which is particularly useful for updating JavaScript libraries.
- **Built-in CDN Support**: It supports loading from cdnjs.com and unpkg.com, making it ideal for such tasks.
- **CSS Loading Support**: Capable of importing CSS resources from the same library, in addition to JavaScript.
### Loading from CDN
Example loading [three.js](https://threejs.org/) from unpkg.com:
```
JSLoader.loadUnpkg(ui, "three", "0.158.0");
```
Example loading [jquery](https://jquery.com/) from cdnjs.com::
```
JSLoader.loadCdnjs(ui, "jquery", "3.7.1");
```
### Loading from Java classpath
Example usage loading script and css file from Java classpath. Typically in src/main/resources in Maven projects.
```
JSLoader.loadJavaResource(ui, MyClass.class, "myScript","myscript.js", "myscript.css");
```
Dynamic JavaScript loader for Vaadin version 2.4.0
Support for Vaadin 24 and 25.