简体   繁体   中英

Does GWT optimize embedded javascript?

It is well known that GWT compiles the Java source to an optimized Javascript . It will for example eliminate all unused functions. This is useful if you use a third party library such as gwtQuery .

I wonder if there is a way to let GWT also optimize the Javascript you embed in the HTML page with the <script> tag. For example instead of letting the user download the full JQuery Javascript library, only download the few functions that are used.

If you are talking about extra <script> tags you add to the page, the answer is no - how could it? You are adding those tags to the html page, and GWT has no way of knowing what they are going to be, or changing where they come from, at least not without rewriting the html file itself (and that isn't how GWT does its work).

If you are talking about putting JS into a JSNI method in your application, then the answer is 'sort of' or 'it depends'. If using GWT 2.4 or earlier, then only very limited optimizations are performed, such as interning strings and inlining very simple methods. If you are using GWT 2.5 or later and have the Closure Compiler option enabled, then Closure will modify all source in the compiled output, including JSNI methods. Note that this optimization may break some JS source if it isn't designed with Closure in mind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM