如何缓存DWR生成的JS文件
To plugin this new Interface Processor, we need to add init parameter for DWRServlet in web.xml. The snippet from web.xml would look like:
<servlet><servlet-name>dwr-invoker</servlet-name><servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class><init-param><param-name>interface</param-name><param-value>util.dwr.HttpCachingInterfaceProcessor</param-value></init-param>...</servlet>
After adding the custom inerface processor following are the headers for the dwr interface request.
GET /dekohportal/dwr/interface/locationchooser.js HTTP/1.1Host: localhostUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5Accept-Language: en,as;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveHTTP/1.x 200 OKServer: Pramati Server/5.0SP3 [Servlet/2.4 JSP/2.0]Date: Tue, 24 Jul 2007 05:49:43 GMT Last-Modified: Tue, 24 Jul 2007 05:49:33 GMTTransfer-Encoding: chunkedConnection: Keep-Alive
Notice that now for the first request, DWR is sending the Last-Modfied header. When we make the second request, the browser sends an “If-Modified-Since” header and DWR now sends a 304 NOT_MODIFIED response.
GET /dekohportal/dwr/interface/locationchooser.js HTTP/1.1Host: localhostUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5Accept-Language: en,as;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 300Connection: keep-aliveIf-Modified-Since: Tue, 24 Jul 2007 05:49:33 GMT HTTP/1.x 304 NOT_MODIFIEDServer: Pramati Server/5.0SP3 [Servlet/2.4 JSP/2.0]Date: Tue, 24 Jul 2007 05:50:42 GMTContent-Length: 0Connection: Keep-Alive
Thus, by plugging in a custom interface processor, we can enable caching of interface java-scripts in DWR.
?
原文:http://blogs.dekoh.com/dev/2007/07/24/caching-dwr-interface-java-script-files/