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.
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.
Advantages of Using ScriptInjector are
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With