Page 1 of 1

Compress html pages with gzip

PostPosted: Mon Jun 11, 2012 10:54 am
by Matts
Hi,

I've seen in the Subsonic 4.0.beta1 - Apr 23, 2010 changelog : "Tech: Compress html pages with gzip."

However, when I have a look at http headers or use a test-site like http://www.whatsmyip.org/http-compression-test/ or http://www.gidnetwork.com/tools/gzip-test.php , it seems that the pages sent by Subsonic are not gzipped.

Is there something I should do to enable this feature ? Did I miss something ?

(I'm using Subsonic directly with jetty)

Thanks,
Matt's

Re: Compress html pages with gzip

PostPosted: Mon Jun 11, 2012 9:14 pm
by ytechie
I don't think the current subsonic pages are compressed. I think that the more important thing right now is to remove the whitespace caused by the jsp. There is a way to remove the whitespace in java containers, but I have not been able to get it to work. Instead - and I know this sounds crazy - I spent a few hours carefully minimizing the main pages and putting everything on one line. While this did speed up my load times a bit, it is not very practical and wouldn't be necessary if we found a way to get rid of the whitespace caused by jsp.

Re: Compress html pages with gzip

PostPosted: Mon Jun 11, 2012 9:44 pm
by Matts
I managed to enable gzip compression by modifying jetty/nnnn/webapp/WEB-INF/web.xml, adding :

Code: Select all
  <filter>
    <filter-name>GzipFilter</filter-name>
    <filter-class>org.mortbay.servlet.GzipFilter</filter-class>
    <init-param>
      <param-name>mimeTypes</param-name>
      <param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>GzipFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


ytechie, to my opinion, removing whitespaces to reduce bandwidth usage will be a lot less efficient than enabling compression. Maybe you can try my solution and tell me how it works for you?

Sindre, perhaps could you include this filter into the war's web.xml, so compression will be enabled by default ? (and so I will not have to re-enable it everytime I upgrade Subsonic ;))
And, just being curious, what was the modification you made to Subsonic when you added "Compress html pages with gzip." to 4.0 changelog ?

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 2:59 am
by ytechie
Does compression only help with bandwidth, or does it speed up load time as well?

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 4:48 am
by hakko
Modern JSP engines have a possibility to pre-compile the pages and remove whitespaces. It actually makes quite a difference.

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 9:25 am
by ytechie
hakko wrote:Modern JSP engines have a possibility to pre-compile the pages and remove whitespaces. It actually makes quite a difference.


That's what I thought, but I could not get Jetty to do it. It is supposed to be pretty simple - it is a filter.

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 9:44 am
by hakko
When I looked into it, I made a note that Subsonic uses Jetty version 6, which is getting old and now is in maintenance mode. The current JSP support is based on jasper 6.0.13 from Apache Tomcat, which doesn't support precompilation of JSPs. So you'd probably need to upgrade Jetty and start using Glassfish support for JSP 2.1 instead.

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 1:16 pm
by Matts
ytechie, compression helps for both bandwith and load time, because if less information goes through the network, the browser will get the data he needs quicker, so load time will be shorter.

I've done some informal tests (with browser's cache disabled) and my feeling is that the load time gain is significant, especially for the left panel, in which I have a lot of artists.

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 7:20 pm
by ytechie
The left panel was slow until 4.7. What version of subsonic are you using?

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 7:37 pm
by Matts
4.7.beta2 (build 3011)

Re: Compress html pages with gzip

PostPosted: Tue Jun 12, 2012 11:30 pm
by ytechie
So you got compression to work successfully. If we add minimization which includes whitespace removal, we could speed it up even further!

But here is another idea that I was thinking of. How about the ability to not load any artists in left.jsp. When you click on a letter the artists for that letter are loaded.