Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding external js in gwt

I writed and checked my js code in GWT. For checking I added my js code in (projectName).html file and it is worked.

But when I try added external js file I get an error:

WARN] 404 - GET <path to js file>someJsFile.js (127.0.0.1) 1452 bytes
         Request headers

I added this line to (projectName).gwt.xml file:

<script src="src/main/resources/<projectName>/someJsFile.js"></script>
like image 711
P0ulBogd Avatar asked Feb 14 '26 23:02

P0ulBogd


1 Answers

To use this technique you have to place your someJsFile.js in your public folder so as the gwt compiler copy it to the final folder where it places the html and js stuff.

If you are using maven you have to check if the resources plugin is copying this file to the war and in which path.

By the way, there are other techniques to insert external javascript in your document:

  • Placing the script tag in your .html file.

  • Using ScriptInjector.fromUrl().

  • A better approach is to use a TextResource and ScriptInjector.fromString() so as the compiler reads the javascript file and includes the content in the final compiled file.

  • You can use gwtquery Ajax.getScript to get the script via ajax and inject it in the dom.

  • A new way, recently added to gwtquery, allows you to include your javascript as a JSNI block, so as the compiler can optimize and obfuscate it.

I'd rather the last one because it offers much more advantages.

like image 109
Manolo Carrasco Moñino Avatar answered Feb 16 '26 11:02

Manolo Carrasco Moñino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!