Ramon Smits

Tell me your secrets and i'll tell you mine

Recent Posts

Tags

Community

Email Notifications

Patterns & Practices / Guidelines

EntLib

Nant

Blogs that I monitor

Archives

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

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.

Comments

Michele said:

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!

# January 16, 2007 10:36 PM

Ramon Smits said:

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.

# January 17, 2007 12:50 AM

Dave said:

That's fine though, keep that viewstate compressed,  that postback from client is important to keep trim, can also use a key and store it local to the server. And also have something like big-ip do the compression so iis doesn't have to.

# July 16, 2009 7:17 AM

Mojtaba said:

another point is that sometimes we publish the site on a host and we don't have access to iis .and this would be the only solution to compress viewstate

# April 18, 2010 6:24 AM

Nick Gilbert said:

I don't agree with this article at all. I'm certain you've not tested the theory. HTTP compression does NOT compress the viewstate on the postback (which on most ADSL connections, is the much slower part of the trip). Therefore although the browser will receive the viewstate compressed, it will send back a totally uncompressed version over a much slower speed connection (typcially ADSL is limited on upload to 256Kbps or 512Kbps).

# April 29, 2010 4:46 PM

Ramon Smits said:

When your viewstate contains lots of data like more then 1kb then you have other problems!! Start by disabling viewstate on lots of controls that don't need it. Doing both viewstate and page compression is a waste of CPU time.

# April 29, 2010 8:35 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 8 and 4 and type the answer here: