Pages

Friday, 20 September 2013

GWTModuleBase URL and HostPageBase URL

http://stackoverflow.com/q/12615663

Say I'm hosting a project at http://example.com/foo. I put all of the GWT files (which are generated in the /war/ directory after compiling) in http://example.com/foo/GwtModule directory.
Then on my host page, which is http://example.com/foo/bar, I put the following in the HTML:
<script type="text/javascript" src="http://example.com/foo/GwtModule/GwtModule.noCache.js"></script>.
My questions are:
  • Will GWT know to fetch its resources (e.g css files) from foo/GwtModule folder rather than trying to get them from foo/bar folder?
  • If I wanted to send a HTTP request to foo/signup, would GWT.getModuleBaseUrl() + "signup" work or will I have to parse the base url, remove "/bar" from it and replace it with "/signup"?
  • If I run the code locally as well as on a web server, will GWT automatically determine if the base url is http://localhost/foo/bar or http://example.com/foo/bar , or do I need to hard-code the base urls somewhere?
 http://stackoverflow.com/a/12618532
Will GWT know to fetch its resources (e.g css files) from foo/GwtModule folder rather than trying to get them from foo/bar folder?
Yes.
GWT always resolves the module base from the script URL (or a special <meta name='gwt:property'>)
If I wanted to send a HTTP request to foo/signup, would GWT.getModuleBaseUrl() + "signup" work or will I have to parse the base url, remove "/bar" from it and replace it with "/signup"?
GWT.getModuleBaseURL() will be /foo/GwtModule/.
You can either use GWT.getModuleBaseURL() + "/../signup" or "GWT.getHostPageBaseURL() + "/signup", in your case they'll both resolve to the same /foo/signup URL.
If I run the code locally as well as on a web server, will GWT automatically determine if the base url is http://localhost/foo/bar or http://example.com/foo/bar, or do I need to hard-code the base urls somewhere?
See answer to first question.
That means you'll have to use <script src="GwtModule/GwtModule.nocache.js"> or <script src="/foo/GwtModule/GwtModule.nocache.js"> in your host page.

No comments:

Post a Comment