Enable gzip compression for scripts?

1 view
Skip to first unread message

goodwill

unread,
Jan 22, 2007, 1:39:24 AM1/22/07
to Castle Project Development List
Just want to see if there is such possibility to do so? I think that
would make the request gain quite a lot of speed- Prototype already
taking 140ms to load even if its on local machine, so compressing it
would probably help.

Ayende Rahien

unread,
Jan 22, 2007, 1:41:03 AM1/22/07
to castle-pro...@googlegroups.com
We serve them all from FilesController, no?
We can certainly make it use gzip compression.
Two other things that we want to do is to put it in the system cache, so it will be served by http.sys from kernel mode.

goodwill

unread,
Jan 22, 2007, 8:43:11 AM1/22/07
to Castle Project Development List
How can we enable the gzip compression?
I don't have knowledge on the system cache portion :) but I would have
interest to understand more :P give me some leisure reading?

Ayende Rahien

unread,
Jan 22, 2007, 9:21:05 AM1/22/07
to castle-pro...@googlegroups.com

josh robb

unread,
Jan 22, 2007, 10:04:19 AM1/22/07
to castle-pro...@googlegroups.com
There is an IHttpModule which enables gzip compression for asp.net without any dependencies on IIS. It's part of that portal thing.. ummm.... DotNetNuke. Not sure about licensing - but it's worth looking at. (The DNN core team just enabled it by default on their latest release for performance reasons).

j.

josh robb

unread,
Jan 22, 2007, 10:14:19 AM1/22/07
to castle-pro...@googlegroups.com
Quick followup:

I saw this mentioned by Shaun Walker in this blog post[1]. I also saw that DNN is BSD licensed.

j.

[1] http://www.dotnetnuke.com/Community/BlogsDotNetNuke/tabid/825/EntryID/1209/Default.aspx

Jason Nelson

unread,
Jan 22, 2007, 5:13:50 PM1/22/07
to castle-pro...@googlegroups.com
An HTTP module using .NET 2.0 that does the same...

namespace Nterface.Framework.HttpModules
{
using System;
using System.IO;
using System.IO.Compression;
using System.Web;

using Nterface.Helpers;

public class HttpCompressionModule : IHttpModule
{
void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(this.CompressContent);
}

/// <summary>
/// EventHandler that gets ahold of the current request
context and attempts to compress the output.
/// </summary>
/// <param name="sender">The <see cref="HttpApplication"/>
that is firing this event.</param>
/// <param name="e">Arguments to the event</param>
void CompressContent(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;

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

string url = app.Request.Url.AbsoluteUri;

// No encoding headers found, do nothing
if (encodings == null)
{
return;
}

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

// Determine the encoding
encodings = encodings.ToLower();

if (encodings.Contains("gzip"))
{
app.Response.Filter = new GZipStream(baseStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
app.Context.Trace.Warn("GZIP compression on");
}
else if (encodings.Contains("deflate"))
{
app.Response.Filter = new DeflateStream(baseStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
app.Context.Trace.Warn("Deflate compression on");
}
}

void Dispose() { }

Colin Ramsay

unread,
Jan 22, 2007, 5:19:39 PM1/22/07
to castle-pro...@googlegroups.com
That looks very handy Jason. Are you using this in production?

Jason Nelson

unread,
Jan 22, 2007, 5:23:33 PM1/22/07
to castle-pro...@googlegroups.com
Yeah, we've been using it on two production sites (www.carbonmade.com,
and www.messandnoise.com) that both push over 5M page views a month.
Works well.

Ron Grabowski

unread,
Jan 22, 2007, 6:03:04 PM1/22/07
to castle-pro...@googlegroups.com
I believe its HttpCompress (for 1.1 and 2.0) from Ben Lowery:

http://www.blowery.org/code/httpcompressionmodule.html

----- Original Message ----

From: josh robb <josh...@fastmail.fm>

To: castle-pro...@googlegroups.com

Sent: Monday, January 22, 2007 10:04:19 AM

Subject: Re: Enable gzip compression for scripts?

goodwill

unread,
Jan 22, 2007, 9:30:31 PM1/22/07
to Castle Project Development List
I think we should go ahead and implement this? :P

josh robb

unread,
Jan 23, 2007, 6:14:50 AM1/23/07
to castle-pro...@googlegroups.com
Fantastic! That's really cool - is this BSD licensed? Can it be contributed to the project - can I take it and make millions selling it on ebay to suckers?
 
My only comment is that this:
 
           if (encodings.Contains("gzip"))
 
 
Is vulnerable to the turkish "i" (and other locale related) encoding bug unless your somehow keeping the locale invariant at the thread/request level. Current best practice is to use the new StringComparsion.Ordinal (or OrdinalIgnoreCase)[1].

j.

Ayende Rahien

unread,
Jan 23, 2007, 9:59:06 AM1/23/07
to castle-pro...@googlegroups.com
Check this out, very relevant:
http://west-wind.com/weblog/posts/10294.aspx
Reply all
Reply to author
Forward
0 new messages