Java (Tomcat): how to configure a cookieless subdomain to serve static content
One of the tip given by both Google and Yahoo! to speed up webpages loading is to configure a cookieless subdomain to server static content.
How do you configure a "cookieless subdomain" using Tomcat in standalone mode (this question is not about how to use Apache to serve static content in a cookieless-way, but about how to do it in Tomcat-standalone mode)?
Note that I don't care about filters supporting If-Modified-Since
nor care about filters supporting gzipping: the static content I'm serving is forever cacheable (or its name will change) and it is already compressed data (so gzip would only slow down the transfer).
Do I need two different Tomcat webapps? (one "cookiefull" and one "cookieless")
Do I need two differe开发者_运维问答nt servlets? (as of now I've got only one dispatcher/controller servlet).
Why would a "regular" link to, say, a static image be called in a cookiefull way when it would be on the same domain as the main webapp and then be called in a "cookie-less" way when it is on a subdomain?
I don't understand exactly what is going on: is it the browser that decides to append or not cookies to the query? If so, why would it not append the cookies to a static query on a "cookieless" subdomain.
Any example as to what is going on behind the scene is most welcome :)
You just need to setup another domain. It can point to the same webapps. Just make sure you don't drop cookies on this new domain.
For example, you main site is
www.example.com
and you can have another domain
static.example.com
For your cookie-less static resources. They can point to the same hosts, go to the same Servlet. You just need to make sure in your app that you don't drop cookies for these static contents.
EDIT: Assuming your static content is served by the default servlet in Tomcat, you don't have to do anything. It doesn't drop cookies for you so your new domain should be cookie free.
If you have to process the static content in the same servlet, you can do something like this,
if (!request.getServerName().equals("static.example.com")) {
// Drop cookie
}
This example assumes you don't drop cookie in your root domain (.example.com). If you do that, you have to get another domain, like examplecdn.com.
I posted about this here: URL/Subdomain rewrites (htaccess)
think you may have it backwards, (or very possibly I do) to clarify, if your implementing a cookie-less subdomain & have a base URL of www. Atleast in this case cookies are set on www, for example: a major cookie setter is google analytics, so when setting their script on my site it looks like this:
`var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'analytics-acc-#],
['_setDomainName', '[
www.valpocreative.com]2'],
['_trackPageview']);
`
You can see here that i set my main domain to www, correct me if i'm wrong in my case I would need to redirect www to non www subdomain & not the other way around. This is also the cname setup made on my cpanel (cname= "cdn" pointing to www.domain.com)
精彩评论