开发者

When is it worth compressing the ViewState?

I agree that the best way to shorten the ViewState is to disable it on the ASP.Net controls that don’t need it. Keeping it small from the beginning is a great habit.

I have also heard that it is already compressed (although can be true… there are ways of compressing it even more, has described in this Stack Overflow question).

My question here is not if i开发者_Python百科t should be compressed… is: when should ViewState be compressed?

If we have a ViewState of 410 characters it will weight 410 bytes in a page, while a ViewState of 13.843 characters equals 13.5 KB.

13.5KB is a considerable weight already. And if I compress a CSS file that height 10KB, I think it is also worthy compressing a ViewState of 13.5KB, even if that means a little extra “thinking” on the server.

But is 410 bytes of ViewState worth the extra processing on the server? At what point is it worth compressing?


There are 3 factors to consider here:

  1. the speed of the server - can it handle the added load of compressing the viewstate, and I am guessing the answer is yes in most cases,
  2. the communication time getting the data to the client, which is something that should be minimized as much as possible, and
  3. the speed of the client - can it handle the extra task of decompressing the viewstate, and again, yes, it probably can. Gzip, etc. is very common these days and modern desktops and browsers are well equipped to handle this.

I say do it, it's all about speeding up communications over that slow (comparatively) Internet link.


If you ask me, the "critical mass" is 10K - if you can check the size before compressing then do it - if less than 10K don't compress otherwise do compress.

Why 10K? Because it will have visible impact almost for sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜