Class ClientResourceLoader

java.lang.Object
com.vaadin.observability.micrometer.ClientResourceLoader

public final class ClientResourceLoader extends Object
Loads a bundled client-side JavaScript resource into a UI exactly once. The classpath resource is read, stripped of comments and executed via Page.executeJs(java.lang.String, java.lang.Object...). A per-UI flag keyed by initKey guards against repeated injection.
  • Method Details

    • loadOnce

      public static void loadOnce(com.vaadin.flow.component.UI ui, String initKey, String resource, Class<?> owner)
      Injects resource into ui once. Subsequent calls with the same initKey for the same UI are no-ops. Missing resources or read failures are logged against owner and otherwise ignored.
      Parameters:
      ui - the target UI; null is ignored
      initKey - the per-UI data key used to ensure single injection
      resource - the classpath resource path of the JavaScript to load
      owner - the class whose class loader and logger are used
    • loadOnce

      public static void loadOnce(com.vaadin.flow.component.UI ui, String initKey, String resource, Class<?> owner, String prelude)
      Injects resource into ui once, preceded by prelude in the same script.
      Parameters:
      ui - the target UI; null is ignored
      initKey - the per-UI data key used to ensure single injection
      resource - the classpath resource path of the JavaScript to load
      owner - the class whose class loader and logger are used
      prelude - JavaScript run immediately before the resource, or null for none. The way to hand the script a server-side decision it cannot read for itself; it is executed as written, so it must be server-authored and must carry no comments, which are stripped from the resource but not from this