Last post Nov 12, 2010 10:57 AM by JonathanWood
Nov 09, 2010 01:50 PM|JonathanWood|LINK
I've spent quite a bit of time on this but seem to be going nowhere. I have a large page that I really want to speed up. The obvious place to start seems to be HTTP compression, but I just can't seem to get it to work for me.
After considerable searching, I've tried several variations of the code below. It kind of works, but after refreshing the browser, the results seem to fall apart. They were turning to garbage when the page used caching. If I turn off caching, then the page
seems right but I lose my CSS formatting (from a separate file) and get an error that an included JS file contains invalid characters.
Most of the resources I've found on the Web were either very old or focused on accessing IIS directly. My page is running on a shared hosting account and I do not have direct access to IIS7, which it's running on.
protected void Application_BeginRequest(object sender, EventArgs e)
// Implement HTTP compression
if (Request["HTTP_X_MICROSOFTAJAX"] == null) // Avoid compressing AJAX calls
// Retrieve accepted encodings
string encodings = Request.Headers.Get("Accept-Encoding");
if (encodings != null)
// Check the browser accepts deflate or gzip (deflate takes preference)
encodings = encodings.ToLower();
if (encodings.Contains("gzip") || encodings == "*")
Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);
Response.Cache.VaryByHeaders["Accept-encoding"] = true;
else if (encodings.Contains("deflate"))
Response.Filter = new DeflateStream(Response.Filter, CompressionMode.Compress);
Response.Cache.VaryByHeaders["Accept-encoding"] = true;
Is anyone having better success with this?
Nov 09, 2010 03:01 PM|atconway|LINK
I have not used HTTP compression myself, but when looking to speed up /optimize a page there are several things you can do to help this. Many times it might require splitting a large page into several smaller individual pages, or using techniques to make
the user think the page is faster (i.e. AJAX and jQuery). If you truly do have a bloated page you can look at reducing what is saved in ViewState or in the rendered HTML itself (i.e. 5 dropdowns with 3,000 items each is not good for performance).
Sometimes poor coding can cause pages to appear slow as well, so it is difficult to always isolate to a single issue.
Someone else might chime in to the compression topic, but in the meantime, take a look at a few of the following links:
Speed Up Your ASP.NET Pages:
Speed Up Your Site! 8 ASP.NET Performance Tips:
High Performance ASP.NET - Speeding Up ASP.NET Pages:
Nov 09, 2010 03:08 PM|JonathanWood|LINK
Thanks, I don't have a problem with links like these (although they are a bit dated) but, as indicated, I've spent a great deal of time on this and feel I have a good understanding of most of these issues.
In the end, if the page has a lot of content, HTTP compression is one way you can make it more efficient. In my case, it would be something worth trying, if I could make it work.
Nov 10, 2010 07:57 AM|toas1|LINK
Just to continue Allens answer:
(and stylesheet) includes late in your page. Another tip is to always combine, cache and compress your script and stylesheets. A good "tool" for this is to use a
Nov 10, 2010 08:05 AM|toas1|LINK
Have you tried using
httpCompress from blowery? Its not the best way but since have no access to IIS7 to set up compression in the server this might be the best way...
Nov 10, 2010 12:31 PM|JonathanWood|LINK
I don't know who Allen is, who you referred to. But I don't have a lots of different CSS and JS files, and I don't believe this particular page uses AJAX at all.
There are other techniques for speeding things up and I've been working on them, but HTTP compression remains an important one that is recommended by Google. Seems like it should be available.
I'll look at the httpCompress code, but am still at a loss as to why I need a third-party solution for this.
Nov 11, 2010 10:26 AM|atconway|LINK
I don't know who Allen is, who you referred to.
Since this is an implementation specific question using HTTP Compression and not really an architecture question, you might have more luck re-posting on the following forum which does get buzz from time to time on HTTP Compression:
HttpHandlers and HttpModules:
Lastly, if for some reason you can't get it working, re-architecting your large pages into smaller individual pages is sometimes the best solution. It might not be the one you want, but at the end of the day big, fat, pages, are slow. Compressing them
might help but if you have a bloated ViewState with tons of controls, long server callbacks, and tons of markup, I don't think there is any button push method to speed it all up without a little redesign. Things like AJAX give a facade to a faster
working page through tools like an Update panel, but are really only giving an appearance of a faster process (with added UpdateProgress gadgets), but really can be just as slow overall. It just makes the user
think the page is a lot faster (when in reality it might only be a little bit because the full page cycle still ran).
Nov 11, 2010 01:02 PM|JonathanWood|LINK
Actually, I don't really care about the implementation. Getting any sort of HTTP compression working would help. And I do not understand why the samples I find on the web don't work, or why no one seems to know anything about this when I post about it in
online forums. But I will try posting at the link you provided.
As far as re-architecting, again, I've spent quite a bit of time on this. It is a mistake to assume I'm looking at only HTTP compression just because, yes, I would like to implement it.
Nov 12, 2010 09:50 AM|rareddy|LINK
How big is the page?
Nov 12, 2010 10:57 AM|JonathanWood|LINK
It's substantial. Why?