Don't use viewstate compression! Use http compression instead!

Published 1 September 6 12:19 AM | Ramon Smits
Just google a bit with the keywords compression plus viewstate and lots of articles are to be found about this subject like this one. The problem is that in most situations programmers are doing something that the webserver already can do for you. Not only does it compress the viewstate, it compresses all (dynamic ) documents that you configure it do to. It becomes even worse when the webapplication compresses its viewstate and the webserver compresses the rendered page output *again*. Seems a bit inefficient to me :-)

So let the webserver do in what it is good at. Serving/streaming rendered documents to the browser in the most efficient manner. Just configure it so that it is also compresses dynamic pages. If you dont know how to do this then just google on http compression iss and lots of articles that explain how to achieve this. It really doesn't need an extra article from my hand ;-)

One situation in which it could be of interest is when an http 1.0 browser performs a request which does not support gzip compression. This way you can achieve nice results by compressing the viewstate. But in the article mentioned at the beginning of the page can be read that the viewstate would sometimes be larger then 1 megabyte. Well if that is occuring in your application then the viewstate data must be *really* expensive to calculate or read from a store must it be that important to add as viewstate data. In most application retrieving data from a data source actually performs very well although it always depends on the total count of page request, the total amount of webservers in a farm and the number of databases as is the kind of state required for some functionality.
Filed under: , ,

Comments

# Michele said on January 16, 2007 10:36 PM:

Hello,

  well, http compression works only from the server to the client, but when the client does a postback, the viewstate is sent to the server uncompressed! This is why compressing (and uncompressing) the viewstate is useful... you know, most of the adsl connectivity has a very low upload bandwidth, so it is hard to send 60k of viewstate for each postback... :S

cu!

# Ramon Smits said on January 17, 2007 12:50 AM:

I did not know that the browser does not compress its POST data when the previous GET/POST returned compressed. So thanks for that comment!

But when you have a viewstate of 60k+ then you have a design issue. I really don't see why you would ping/pong that much data on a round-trip. This will result in a double compress. First the viewstate and then http compression for the html.