GZip output compression with AJAX

Discussion in 'ASP .Net' started by Mike P2, Jun 4, 2007.

  1. Mike P2

    Mike P2 Guest

    Hi. To make page downloading quicker, I added GZipStream into the
    Response filter. My (shortened VB) code snippet from Global.asax looks
    like this:
    ............................................

    Sub Application_BeginRequest(...)

    If Request.RawUrl.Contains(".aspx") And _
    Not Request.Headers("Accept-Encoding") Is Nothing Then

    If Request.Headers("Accept-
    encoding").ToLower().Contains("gzip") Then

    Response.Filter = New GZipStream(Response.Filter,
    CompressionMode.Compress, True)
    Response.AppendHeader("Content-encoding", "gzip")

    ' Else...try deflate

    End If

    End If

    End Sub
    ............................................

    I added the check for .aspx in the request because it was messing up
    images. Now that I'm using AJAX, it's giving me problems again. When
    AJAX (I mean ASP's AJAX thing, but I'm not using Atlas) tries to
    communicate with the server, it (JS) alert()s me that it could not
    parse the server's response, and is probably because of a filter
    (meaning this simple GZip stream).

    How can I more efficiently check whether or not it is appropriate to
    compress the output? And, by the way, is there a better way of
    compressing output that won't mess up with images and could possibly
    compress AJAX also?

    -Mike PII
    Mike P2, Jun 4, 2007
    #1
    1. Advertising

  2. Did you ever find a solution to this? I am having the same problem. If I
    enable compression on our ISA server, it works fine. Just when using an
    HTTPModule is when I have this problem. Very frustrating.

    "Mike P2" wrote:

    > Hi. To make page downloading quicker, I added GZipStream into the
    > Response filter. My (shortened VB) code snippet from Global.asax looks
    > like this:
    > ............................................
    >
    > Sub Application_BeginRequest(...)
    >
    > If Request.RawUrl.Contains(".aspx") And _
    > Not Request.Headers("Accept-Encoding") Is Nothing Then
    >
    > If Request.Headers("Accept-
    > encoding").ToLower().Contains("gzip") Then
    >
    > Response.Filter = New GZipStream(Response.Filter,
    > CompressionMode.Compress, True)
    > Response.AppendHeader("Content-encoding", "gzip")
    >
    > ' Else...try deflate
    >
    > End If
    >
    > End If
    >
    > End Sub
    > ............................................
    >
    > I added the check for .aspx in the request because it was messing up
    > images. Now that I'm using AJAX, it's giving me problems again. When
    > AJAX (I mean ASP's AJAX thing, but I'm not using Atlas) tries to
    > communicate with the server, it (JS) alert()s me that it could not
    > parse the server's response, and is probably because of a filter
    > (meaning this simple GZip stream).
    >
    > How can I more efficiently check whether or not it is appropriate to
    > compress the output? And, by the way, is there a better way of
    > compressing output that won't mess up with images and could possibly
    > compress AJAX also?
    >
    > -Mike PII
    >
    >
    =?Utf-8?B?YmlrZW1pa2U=?=, Jun 6, 2007
    #2
    1. Advertising

  3. Mike P2

    Mike P2 Guest

    On Jun 6, 8:50 am, bikemike <>
    wrote:
    > Did you ever find a solution to this? I am having the same problem. If I
    > enable compression on our ISA server, it works fine. Just when using an
    > HTTPModule is when I have this problem. Very frustrating.


    No, I haven't found a solution yet. This is frustrating me too. GZip
    compression is a pretty common thing, I'm sure it's been done
    successfully in ASP.net and there are people in this newsgroup who
    have the solution.

    -Mike PII
    Mike P2, Jun 6, 2007
    #3
  4. Mike P2

    Mike P2 Guest

    Ok, I tried using

    If Request.Headers("Accept").Contains("html") Or
    Request.Headers("Accept").Contains("xml")) Then

    instead to decide whether or not to compress the output with GZ and my
    other filter that takes out some whitespace, but that's not helping
    either. I guess ASP.net AJAX is served by the same page it's on
    instead of ScriptResource.axd or whatever. So what can I do?

    -Mike PII
    Mike P2, Jun 11, 2007
    #4
  5. I did find a solution to this problem that is not resolved with GZip in .NET,
    but in IIS. Basically all I did was enable compression for only my virtual
    directory in IIS. For whatever reason, the AJAX code does not have any
    problems with this and it works great. I am getting nearly 90% compression
    on my returned code now. After spending a day trying to make the .NET
    solution work, I gave up and looked for alternative solutions. Fortunately,
    the built-in IIS compression did the trick. If you need help on how to
    enable it for just a single web or virtual, let me know.

    "Mike P2" wrote:

    > Ok, I tried using
    >
    > If Request.Headers("Accept").Contains("html") Or
    > Request.Headers("Accept").Contains("xml")) Then
    >
    > instead to decide whether or not to compress the output with GZ and my
    > other filter that takes out some whitespace, but that's not helping
    > either. I guess ASP.net AJAX is served by the same page it's on
    > instead of ScriptResource.axd or whatever. So what can I do?
    >
    > -Mike PII
    >
    >
    =?Utf-8?B?YmlrZW1pa2U=?=, Jun 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad A. Beckner

    GZip Compression for IIS 5.0/ASP .NET

    Chad A. Beckner, Jun 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    536
    Landi
    Jul 23, 2004
  2. Anders K. Jacobsen [DK]

    Gzip compression and ASP.NET

    Anders K. Jacobsen [DK], Dec 30, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,649
    Joerg Jooss
    Dec 31, 2004
  3. Showjumper

    Enabling GZip in MS Ajax

    Showjumper, Sep 4, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    379
    Michael Nemtsev, MVP
    Sep 4, 2007
  4. Szymon Rozga

    Trouble with gzip output compression

    Szymon Rozga, May 25, 2006, in forum: Ruby
    Replies:
    1
    Views:
    116
    Robert Klemme
    May 26, 2006
  5. Fernando Silva

    Gzip compression with SOAP

    Fernando Silva, Dec 29, 2009, in forum: Ruby
    Replies:
    0
    Views:
    172
    Fernando Silva
    Dec 29, 2009
Loading...

Share This Page