问题
Our application has many large GWT modules developed over time. Architecture is Servlets/JSP and GWT.
I am simplifying here. Link1.jsp
contains Link1 GWT module
Link2.jsp
contains Link2 Gwt module
Link3.jsp
contains Link3 GWT module
.
All the above 3 jsps are same, ie, include same header and footer. Only body is changing based on the GWT module.
Now, we are trying to improve the performance while the user is clicking the above links.
When the user is clicking Link1.jsp
, the request is sent to server and the response
is coming back in 500-700ms.(We are in India and hence the latency issues)
The user is complaining about the slowness of the application for every link click.
Hence, we are trying the following:
Since all the jsps are exactly same and only the body is changing, we decided not
to make default href request
for the above links and we are trying to load the different
GWT modules based on the click link using JQuery.
回答1:
I did answer this question a while ago. Basically, compile your modules using the xsiframe
linker and load your modules using dinamically generated <script>
tags:
$("#clickMe").click(function() {
$('body').append($("<script src=foo/foo.nocache.js />"));
}
Update:
Trying to figure out why you need this architecture, IMO maybe you are trying a wrong solution.
If all of your app is based in GWT modules, why to introduce external javascript libraries?
GWT has its own mechanism to face the problem of speeding up the initial loading. I think you should create a super-gwt-module which includes all sub-modules you have in your application.
- The super module would be the unique
EntryPoint
in your app, and the responsible to handle the links in your jsp. Probably I would use gwtquery for that module, but it is up to you. - Other modules should be loaded using code-splitting, so they are not
EntryPoint
butRunAsyncCallback
.
The advantages of this solution are a lot. And you will have an application which loads really fast:
- You dont load external libraries like jquery: about 100KB compressed.
- The first fragment to load would be super-small, probabely 30-50 KB if you use gquery (much less than jquery itself)
- Many of the code shared by the modules (gwt-core, jre, etc), could go to the first fragment and would be shared by all the modules, decreasing the final downloaded size of each module.
- It is an out-of-the-box solution, gwt compiler makes a good job splitting the code and adding everything to load it asynchronously when demanded.
- Configuring correctly your webserver, clients would cache the app for ever.
- Java ecosystem facilitates modular apps.
Another options in GWT-2.5.1 to decrease js size are:
- Remove stack code:
<set-property name="compiler.stackMode" value="strip"/>
- Pre-compress your js files:
<inherits name="com.google.gwt.precompress.Precompress"/>
- Use the closure compiler:
-XenableClosureCompiler
- Remove class metadata:
-XdisableClassMetadata
- Disable castings:
-XdisableCastChecking
- Optimize code-splitting:
-XfragmentCount 20
来源:https://stackoverflow.com/questions/16983265/how-to-load-gwt-modules-using-the-jquery