Class JSLoader

java.lang.Object
org.parttio.vaadinjsloader.JSLoader

public class JSLoader extends Object
Dynamic JavaScript library loader for Vaadin.
  • Field Details

  • Constructor Details

    • JSLoader

      public JSLoader()
  • Method Details

    • load

      public static void load(com.vaadin.flow.component.Component component, String libraryName, String version, String libraryFile, String urlPattern)
      Loads a JavaScript and CSS files dynamically from given CDN URL. Pattern is used to construct the URL for the library. The pattern can contain named placeholders {library}for the library name and {version} for the version. The placeholders are replaced with the actual values before the URL is loaded. E.g. for unpkg.com: https://unpkg.com/{library}@{version}/dist/{library}
      Parameters:
      component - the UI instance to load the library for
      urlPattern - the base URL pattern to use for loading the library
      libraryName - the name of the library to load
      version - the version of the library to load
      libraryFile - the JavaScript file to load or null
    • loadFiles

      public static void loadFiles(com.vaadin.flow.component.Component component, String urlPattern, String libraryName, String version, String... file)
      Loads a JavaScript and CSS files dynamically from given CDN URL. Pattern is used to construct the URL for the library. The pattern can contain named placeholders {library}for the library name and {version} for the version. The placeholders are replaced with the actual values before the URL is loaded. E.g. for unpkg.com: https://unpkg.com/{library}@{version}/dist/{library}
      Parameters:
      component - the UI instance to load the library for
      urlPattern - the base URL pattern to use for loading the library
      libraryName - the name of the library to load
      version - the version of the library to load
      file - the files of the library to load
    • getLoadedVersion

      public static String getLoadedVersion(com.vaadin.flow.component.Component component, String library)
      Returns the version of the library that has been loaded for the given UI.
      Parameters:
      component - the UI instance to check
      library - the name of the library to check
      Returns:
      the version of the library that has been loaded for the given UI
    • loadCdnjs

      public static void loadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version)
      Loads a minified JavaScript library dynamically from cdnjs.com.
      Parameters:
      component - the UI instance to load the library for
      libraryName - the name of the library to load
      version - the version of the library to load
      See Also:
    • loadCdnjs

      public static void loadCdnjs(com.vaadin.flow.component.Component component, String libraryName, String version, boolean minified)
      Loads a JavaScript library dynamically from cdnjs.com.
      Parameters:
      component - the UI instance to load the library for
      libraryName - the name of the library to load
      version - the version of the library to load
    • loadUnpkg

      public static void loadUnpkg(com.vaadin.flow.component.Component component, String libraryName, String version, String... libraryFile)
      Loads a JavaScript library dynamically from unpkg.com.
      Parameters:
      component - the UI instance to load the library for
      libraryName - the name of the library to load
      version - the version of the library to load
      libraryFile - the file(s) to load or null
    • isLoaded

      public static boolean isLoaded(com.vaadin.flow.component.Component component, String library)
      Check if the given library has been loaded for the UI.
      Parameters:
      component - the UI instance to check
      library - the name of the library to check
      Returns:
      true if the given library has been loaded for the given UI
    • isLoaded

      public static boolean isLoaded(com.vaadin.flow.component.Component component, String library, String version)
      Check if the given library and version has been loaded for the UI.
      Parameters:
      component - the UI instance to check
      library - the name of the library to check
      version - the version of the library to check
      Returns:
      true if the given library and version has been loaded for the given UI