Load JavaScript and CSS from Server Nearby
From Documentation
If some of the client machines are far away from the application server, we could set up a server nearby the clients to host ZK's JavaScript and CSS files, and then configure the application server to generate the URLs of JavaScript and CSS (and iamges it refers) from the the sever nearby clients.
*Notice : the ZK static resource server is a simple server which deploy official ZK library, not whole application of yours.
How to
- Implement the Encodes.URLEncoder
- Add library-property configuration to the zk.xml
- Document : URLEncoder.
Following is a sample :
Configuration
<library-property>
<name>org.zkoss.web.servlet.http.URLEncoder</name>
<value>org.zkoss.test.testEncoder</value> <!-- Where the Class is -->
</library-property>
Implementation
package org.zkoss.test;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.zkoss.web.servlet.http.Encodes.URLEncoder;
public class testEncoder implements URLEncoder {
@Override
public String encodeURL(ServletContext ctx, ServletRequest request, ServletResponse response, String uri, URLEncoder defaultEncoder) throws Exception {
if (uri.charAt(0) == '~' && isStaticResource(uri)) {
return getResourceHost() + uri.replace("~./", "");
} else {
return defaultEncoder.encodeURL(ctx, request, response, uri, defaultEncoder);
}
}
private boolean isStaticResource(String url) {
if (url.endsWith(".wpd") || url.endsWith(".wcs") || url.endsWith(".gif") || url.endsWith(".png"))
return true;
return false;
}
/**
* Detect where the ip is/ who is login / what kind of resouce server will
*
* @return the host name include protocol prefix. (Client will retrieve resource from it)
*/
private String getResourceHost() {
return "http://SomeWhereNearbyMe/DefaultZK/zkau/web/";
}
}
Version History
Last Update : 2010/10/20
Version | Date | Content |
---|---|---|
1 | 10/20/2010 | Add example and how to by using URLEncoder |