?
Solved

Verify that this is an acceptable HttpCompression module?

Posted on 2010-01-09
2
Medium Priority
?
277 Views
Last Modified: 2013-12-17
Hello experts.

I am attempting to improve performance on my site.  I am writing my own http compression module, and I just basically need a few opinions on whether or not this is an acceptable approach.

I am using a lot of Microsoft Ajax on my site (just the stuff that comes with Visual Studio, nothing fancy like Telerik or 3rd party controls)

When I engage this httpModule in my web config, it considerably drops the size of data transfer on each initial page load and ALSO on each subsequent ajax call.  It would appear that everything is working fine.  However, I am kind of feeling that this is too easy, and that I am perhaps missing something very important.  

Please review the below code and give me your thoughts.  Thank you!
public class HttpCompressionModule: IHttpModule
    {
        public void Dispose()
        {

        }

        public void Init(HttpApplication application)
        {
            application.BeginRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            string currentPath = app.Request.CurrentExecutionFilePath;
            string ext = Path.GetExtension(currentPath).ToLower();

            switch (ext)
            {
                case ".axd":
                    return;
            }

            // Accepted encodings
            string encodings = app.Request.Headers.Get("Accept-Encoding");

            // No encodings; stop HTTP Module processing
            if (string.IsNullOrEmpty(encodings))
                return;

            // Current response stream
            Stream baseStream = app.Response.Filter;

            // Determine the requested encoding
            if (encodings.Contains("gzip"))
            {
                app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress);
                app.Response.AppendHeader("Content-Encoding", "gzip");
            }
            else if (encodings.Contains("deflate"))
            {
                app.Response.Filter = new DeflateStream(baseStream, CompressionMode.Compress);
                app.Response.AppendHeader("Content-Encoding", "deflate");
            }
        }
    }

Open in new window

0
Comment
Question by:Gewgala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
Deathrace earned 2000 total points
ID: 26277396
Hey,
Nice try, one more article to help you
http://www.codeproject.com/KB/aspnet/httpcompression.aspx
0
 
LVL 7

Author Closing Comment

by:Gewgala
ID: 31675060
Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question