app not reload from android chrome

100 views
Skip to first unread message

pierre...@gmail.com

unread,
Jan 11, 2021, 5:34:58 AM1/11/21
to GWT Users
Hi,
I have a gwt app developed with gwt-material but I assume it's not relevant for this problem.
The app is served by Tomcat.
Everything is fine with PC/iphone/iPad but with android after deploying a new app, the old one is still showned. The nocache mecanism doesnot work in android chrome.
Removing the cache works, but I cannot asks that to my users.

Any hint how can I force the browser  to reload the app from server for theses mobiles ?
Thanks in advance
Pierre

lofid...@gmail.com

unread,
Jan 11, 2021, 11:58:42 AM1/11/21
to GWT Users

pierre...@gmail.com

unread,
Jan 11, 2021, 12:11:16 PM1/11/21
to GWT Users
Thanks, I guess so. Will try ...

Peter Donald

unread,
Jan 11, 2021, 4:10:17 PM1/11/21
to GWT Mailing List
There's a library that manages this for you at https://github.com/realityforge/gwt-cache-filter which will set the caching parameters as required.

--
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 google-web-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/cf24a086-3c9e-4488-9ab8-200402a38b4bn%40googlegroups.com.


--
Cheers,

Peter Donald

pierre...@gmail.com

unread,
Jan 12, 2021, 6:42:25 AM1/12/21
to GWT Users
Great thanks,
My case is similar to the "example" example. Only a standalone index.html.
So I add a WEB-INF directory with web.xml and lib/gwt-cache-filter-0.9.jar   and now android phone reload it.
So if I understand correctly the *.cache.js are now always reloaded but quicker as they are gipped before transfer, right ?

best, Pierre

Selçuk Atay

unread,
Jan 12, 2021, 12:49:11 PM1/12/21
to google-we...@googlegroups.com
Hey Pierre,
You can use a special web filter for better handling of caching. 
Here is an example similar to what I use on my projects, 

Add the following to your web.xml
<filter>
<filter-name>gwtCacheControlFilter</filter-name>
<filter-class>com.acme.server.GWTCacheControlFilter</filter-class>
<init-param>
<param-name>Cache-Control</param-name>
<param-value>max-age=31536000, public</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>gwtCacheControlFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

And the doFilter method of your filter class would be something like
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException,
ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();

if (requestURI.contains(".nocache.")) {
Date now = new Date();
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setDateHeader("Date", now.getTime());
// one day old
httpResponse.setDateHeader("Expires", now.getTime() - 86400000L);
httpResponse.setHeader("Pragma", "no-cache");
httpResponse.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
} else if (requestURI.contains(".cache.")) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
// one day old
httpResponse.setHeader("Cache-Control", "public, max-age=31536000");
httpResponse.setDateHeader("Expires", DateUtil.addDays(new Date(), 365).getTime());
}

filterChain.doFilter(request, response);
}
-Selcuk


--
Reply all
Reply to author
Forward
0 new messages