Good point Jens.  Here's some handy code that works well for me:

In the HttpServlet that servers up the index.html file:

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
  String serverVersion =  [LOAD YOUR SERVER VERSION]
  String quotedETag = "\"" + serverVersion + "\"";

  response.setHeader("ETag", quotedETag);
  response.setHeader("Cache-Control", "no-cache, must-revalidate");

  String ifNoneMatch = request.getHeader("If-None-Match");

  // The browser has the latest version
  if (quotedETag.equals(ifNoneMatch)) {
    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); // 304 Not 
Modified
  }
  // The browser needs the latest version
  else {
    String html = [LOAD YOUR HTML]
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().append(html);
  }
}

You need a serverVersion somehow.  If using Google App Engine, you can do  
System.getenv("GAE_VERSION");  otherwise, it's up to you how you get it and 
make it unique for each deploy.

On Friday, 13 February 2026 at 8:52:48 pm UTC+11 Jens wrote:

> Yeah, using the gwt property is the easiest solution. I also use it. But 
> be aware that you now have to update your webserver configuration to tell 
> the browser to not cache the index.html anymore. Otherwise the embedded GWT 
> code will be outdated if you deploy an updated version of your GWT app and 
> all the hashes of *.cache.js files have changed.
>
>
> -- J.
>
> Craig Mitchell schrieb am Freitag, 13. Februar 2026 um 02:00:28 UTC+1:
>
>> Thanks Colin.  Dug around a little and figured out all I needed was:
>>
>> <meta name="gwt:property" content="baseUrl=/dt/" />
>>
>> ("dt" is my GWT module short name)
>>
>> Now everything works, including superdevmode.  Ie: No need for the 
>> gwtNoCacheJs.contains("superdevmode") check anymore.
>>
>> I think my page does load a bit faster now (on subsequent times, not the 
>> first visit).  https://drift.team/ if anyone is curious what the end 
>> result root html source looks like.
>>
>> On Friday, 13 February 2026 at 10:16:23 am UTC+11 Colin Alworth wrote:
>>
>>> I believe that 
>>> https://github.com/gwtproject/gwt/blob/main/dev/core/src/com/google/gwt/core/ext/linker/impl/computeScriptBase.js
>>>  
>>> is what you're going to want to read, or possibly replace on your 
>>> classpath. Alternatively, subclass the CrossSiteIframeLinker to override 
>>> getJsComputeScriptBase(LinkerContext) to provide your own file.
>>>
>>> From that file:
>>> /**
>>>  * Determine our own script's URL by trying various things
>>>  *
>>>  * First - use the baseUrl meta tag if it exists
>>>  * Second - look for a script tag with the src set to 
>>> MODULE_NAME.nocache.js and
>>>  *   if it's found, use it to determine the baseUrl
>>>  * Third - if the page is not already loaded, try to use some 
>>> document.write
>>>  *   magic to install a temporary tag and use that to determine the 
>>> baseUrl.
>>>  * 
>>>  * This is included into the selection scripts
>>>  * wherever COMPUTE_SCRIPT_BASE appears with underlines
>>>  * on each side.
>>>  */
>>>
>>> The "Second" step is where you appear to be getting stuck - since there 
>>> is no script tag with a src attr, the rest of the loading code doesn't know 
>>> what to do. So, add a meta tag for baseUrl so the script knows where the 
>>> other resources are loaded from.
>>>
>>> Note that I haven't messed with this in years, and might have missed a 
>>> point or two.
>>>
>>> On Thursday, February 12, 2026 at 4:54:23 PM UTC-6 
>>> [email protected] wrote:
>>>
>>>> I tried to inject the non-dev nocache.js into my main index.html file.  
>>>> Like this:
>>>>
>>>> String gwtNoCacheJs = loadFileFromServlet("/dt/dt.nocache.js");
>>>>
>>>> if (gwtNoCacheJs.contains("superdevmode")) {
>>>>   gwtNoCacheJs = "<script type='text/javascript' 
>>>> src='/dt/dt.nocache.js'></script>";
>>>> }
>>>> else {
>>>>   gwtNoCacheJs = "<script type='text/javascript'>\n" + gwtNoCacheJs + "
>>>> \n</script>";
>>>> }
>>>>
>>>> String html = loadFile("index.html").replace("XXX", gwtNoCacheJs);
>>>>
>>>> However, it doesn't work, as nocache.js wants to load files from the 
>>>> same sub directory it's located in, and not the root directory.
>>>>
>>>> Has anyone done this?  It probably isn't work the effort, as it'll only 
>>>> save one network call, but I was curious if it's possible.
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/google-web-toolkit/9bdf6a9d-8c4a-43a2-bfef-a9fc865090f3n%40googlegroups.com.

Reply via email to