title: How to serve GWT static files from a CDN
body: <p>I am trying to figure out how to serve my GWT files from a CDN instead of from a tomcat server.</p>
  
  <p>I started with this code</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8" /&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;meta name="robots" content="no-index, no-follow" /&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
  &lt;title&gt;My Site&lt;/title&gt;
  &lt;script type="text/javascript" src="/bcmjs/bcmjs.nocache.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="gwt_div"&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And modified the javascript import to use the CDN url, from this:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/bcmjs/bcmjs.nocache.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>To this:</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://uoo9w.cloudfront.net/bcmjs/bcmjs.nocache.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Hoorah! The js downloads, UIBinder widgets are visible, but RPC fails.</p>
  
  <p>The problem seems to be that <code>GWT.getModuleBase</code> returns the URL of the Javascript (uoo9w.cloudfront.net) instead of the host page (mysite.example.com), which breaks things like the URL used for RPC requests.</p>
  
  <p><strike><code>GWT.getModuleBaseForStaticFiles</code> seems to be a method built allow CDN use, but I can't find documentation about it.</strike> <em>(See comments)</em></p>
  
  <p>Does anyone know of the correct way to set up GWT to serve from a CDN and send RPC request to the host page's domain?</p>
  
  <p>Side Note:</p>
  
  <p>Since the CDN has a different domain name and path, I was worried there were going to be problems involving the Same Origin Policy, but since the GWT host page is served on the same domain as all the RPC requests, this is not a problem. (ie. Window.Location is the same domain as the RPC)</p>