CSS and Images not loading
Alrighty, my first (hopefully) helpful blog :).I am using a hosting company for my webapp. They are using plain, good old Apache for hosting the static content such as images, css files and html pages. Requests are passed to Tomcat for processing any of the jsp files etc.
I noticed that the first time I went to my website after clearing the browser cache, the images and the CSS files were not being displayed or even found. This kept me up a few nights pulling my hair out, but I eventually noticed that when I disabled cookies the images and CSS NEVER got displayed!
The problem? After viewing the page source I noticed that without cookies enabled, the URLs included the session id in them, like so: "http://www.stroke-education.com/image/cart.gif;jsessionid=24A03F5B45814B192ABF9F7B1918B8AB.tomcat36". Of course Apache doesn't know how to deal with the jsessionid, it treats the whole thing as one URL, and it cannot find the file. The session id gets included the first time because tomcat isn't sure if cookies are enabled/disabled.
The solution? Tomcat has to get passed the requests that have jsessionid in the URL. My host company ended up forwarding all requests to Tomcat, which is overkill but it works.
A better solution is talked about here:
http://www.jguru.com/faq/view
They suggest adding the following to Apaches config:
<IfModule mod_rewrite.c>
RewriteEngine on
# Force URLs with a jsessionid to go to Tomcat. Necessary because
# Apache doesn't recognise that the semi-colon is special.
RewriteRule ^(/.*;jsessionid=.*)$ $1 [T=jserv-servlet]
</IfModule>
2 comments:
Hi,
Thanks I have been looking for this sort of info for a long time.
SEO Website Development
My pleasure. I am glad you found it useful. I have just started blogging again, so hopefully my future posts will be of use as well.
Post a Comment