Eleeist
Eleeist

Reputation: 7041

How can I import external JavaScript file?

I need to import a JS file that is hosted on another server and is not part of my application's assets.

How can I import it from within the component?

Upvotes: 6

Views: 1301

Answers (1)

Eleeist
Eleeist

Reputation: 7041

I ended up setting up environmental JavaScriptSupport and calling importJavaScriptLibrary from within setupRender():

@Environmental
private JavaScriptSupport javaScriptSupport;

public void setupRender() {
    this.javaScriptSupport.importJavaScriptLibrary("URL-to-JS-file");
}

Upvotes: 7

Related Questions