How can I import external JavaScript file?
Asked Answered
B

1

6

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?

Bevin answered 1/11, 2012 at 14:46 Comment(2)
for efficiency and reliability, i would strongly recommend downloading the script and hosting it from your application or web server.Ate
The script is generted dynamically by external server so there is no way I can host it myself.Bevin
B
7

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");
}
Bevin answered 1/11, 2012 at 16:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.