admin管理员组文章数量:1431401
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 es 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.
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 es 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.
3 Answers
Reset to default 5The 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
- 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).
You already described one of the key advantages.
Another advantage is that some scripts may never be used. For example, you may have a script that integrates Google Wallet payments or Facebook login, but not every user needs these features every time. So there is no reason to load these scripts until actually needed.
本文标签: javascriptGWT ScriptInjector VS adding script tag to indexhtml pageStack Overflow
版权声明:本文标题:javascript - GWT ScriptInjector VS adding script tag to index.html page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745549900a2662890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论