How to cache DWR interface java script files

I noticed that when we use DWR, there are many requests to java-script files from the browser. It appeared that DWR scripts are not being cached by the browser.

The response headers for the repeat downloads looked like:

Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:1268
Content-Type:text/javascript;charset=utf-8
Date:Tue, 28 Jul 2015 11:27:17 GMT
Keep-Alive:timeout=10, max=498
Server:Apache
Vary:Accept-Encoding

Notice that in the response headers, there is no Last-Modified header. This is the reason why the browser is reloading the script on every page load.This script is a DWR interface script. When you expose java methods using DWR (through a create tag in the dwr-.xml), DWR creates an interface javascript. This file implements javascript methods which invoke the remote java methods (using DWREngine._execute). The interface script does not change unless the methods exposed in the dwr-.xml are changed and the application is restarted. Hence the script should have been cacheable.

How to add Last-Modified in the response?

Answers:

Answer

I'm surprised that this isn't built into DWR. You could always configure a custom Servlet Filter in your web application. It's fair enough to assume that the script won't change for the lifetime of the ServletContext. Perhaps you could store a timestamp as the webapp starts and have the filter set the Last-Modified header for /dwr/*

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.