views:

416

answers:

3

I am looking to improve front-end performance of my application, so I used YSlow tool in Firefox. When I ran this tool for my app, in the YSlow grade tab it showed up a issue 'Grade F on Compress components with gzip'. Seems to be that we need to compress the files(js, css) while sending from the server to client to increase the server response time.

My app is a Struts Java application. Can anyone let me know how to compress and send the front end UI files(JS,CSS) from server so that the response time increases and my pages lot fastly? What are the things that I need to do to compress these files in Java at server?

+4  A: 

I recommend to use a Servlet Filter (since servlet 2.3 spec)

A gzip filter is well documented, so there is no need to reinvent the wheel:

Also, some servlet containers can do gzip on the fly. Take a look at this related question.

Guido
A: 

You normally configure it at appserver/servletcontainer level. I don't know which one you're using, so here's just a Tomcat targeted example. In the /conf/server.xml configure the <Connector> component as follows:

<Connector compression="on">

That's all. Just add compression="on". The other servers provides a comparable setting. consult its documentation for details. Often it's exactly the same because they're built on top of Tomcat.

For more YSlow hints in Java EE webapplication perspective you may find this blog article more useful.

BalusC
I have tried mentioned in this article http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html. But YSlow still shows that the files(JS, CSS) are not sent from the server in compressed mode. Any thoughts/suggestions are appreciated. Thanks
Venkata Sirish
Don't you confuse compression with minification?
BalusC
Yes i think here we need to compress the js,css files and send it to the client from server. plz point me if my understanding is wrong.
Venkata Sirish
It's hard to say since I don't have access to your environment and you are apparently not able to examine/verify the working yourself.
BalusC
As i said earlier, though i compressed at server, still iam able to see 'Grade F on Compress components with gzip' in YSlow. Anyways to achieve gzip compression (JS, CSS) files from the server.
Venkata Sirish
There can be lot of things the cause. Edited the wrong server.xml file, edited the wrong connector, not rebooted the server, tested with files still in browser cache, browser doesn't support compression, etc
BalusC
A: 

Are you sure you are trying to compress JS and CSS rather than trying to minify it? Generally JS and CSS are cached by the browser after the first visit provided your caching headers are set correctly by your web server. In practice I have found that minifying JS and CSS is usually good enough for the initial download by the browser.

There are many JS minifiers. For example one is located here.

CoolBeans