Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT ScriptInjector VS adding script tag to index.html page

Why use ScriptInjector class.

What is the difference between using ScriptInjector to inject a js file and adding the link with a <script> tag directly to the index.html file. Is there any advantage of using the ScriptInjector over adding the script tag in the index.html file.

One thing that comes to my mind is that the initial load may be a lot more if you add a ton of scripts in the index.html file using <script> which are not going to be used until later. ScriptInjector will cut down on the initial load by loading the script asynchronously only when required.

like image 902
Sai Phaninder Reddy J Avatar asked Dec 29 '25 13:12

Sai Phaninder Reddy J


2 Answers

The main advantage of using ScriptInjector is that you can leverage the Java language to inject JS files (or JS code) in your page. In the context of a GWT application, this is cleaner than using JSNI.

You're right, adding the <script> tags up front in the HTML file might lead to performance issues.

like image 166
spg Avatar answered Jan 01 '26 03:01

spg


Advantages of Using ScriptInjector are

  • ScriptInjector Dynamically create script tag and attach it to DOM meaning based on the condition you can inject script(js).
  • If we include lot of Script tag on host page, which will take lot of time to load the script tag(also it will block untill its get executed).
like image 22
mohammed sameen Avatar answered Jan 01 '26 01:01

mohammed sameen



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!