Enable gzip compression for scripts?

1 visning
Hoppa till det första olästa meddelandet

goodwill

oläst,
22 jan. 2007 01:39:242007-01-22
till 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

oläst,
22 jan. 2007 01:41:032007-01-22
till 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

oläst,
22 jan. 2007 08:43:112007-01-22
till 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

oläst,
22 jan. 2007 09:21:052007-01-22
till castle-pro...@googlegroups.com

josh robb

oläst,
22 jan. 2007 10:04:192007-01-22
till 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

oläst,
22 jan. 2007 10:14:192007-01-22
till 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

oläst,
22 jan. 2007 17:13:502007-01-22
till 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

oläst,
22 jan. 2007 17:19:392007-01-22
till castle-pro...@googlegroups.com
That looks very handy Jason. Are you using this in production?

Jason Nelson

oläst,
22 jan. 2007 17:23:332007-01-22
till 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

oläst,
22 jan. 2007 18:03:042007-01-22
till 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

oläst,
22 jan. 2007 21:30:312007-01-22
till Castle Project Development List
I think we should go ahead and implement this? :P

josh robb

oläst,
23 jan. 2007 06:14:502007-01-23
till 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

oläst,
23 jan. 2007 09:59:062007-01-23
till castle-pro...@googlegroups.com
Check this out, very relevant:
http://west-wind.com/weblog/posts/10294.aspx
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden