ASP.NET Web Devs - ContentGator!

DreamThrall

Newbie
Joined
Oct 14, 2003
Messages
3,483
Reaction score
0
Check out my newest open-source project, ContentGator.

ContentGator allows web developers to automatically serve aggregated content (css, js, etc) from their web pages. By simply listing relative paths, files are grouped by content type and aggregated into a single file, which is automatically served in GZip or Deflate compression.

  • Decrease client load times by limiting the number of distinct HTTP requests
  • GZip/Deflate compression decreases load times and bandwidth consumption
  • Allows better organization of your project, since parts can be more liberally separated into separate files
  • Aggregates multiple content files into a single file
  • Supports adding files from both master pages and child pages
  • Both WebForms and MVC Beta (Preview 5) are supported
  • Supports GZip and Deflate compression
  • Implements HTTP 304 Not Modified

EDIT: Please digg :) http://digg.com/programming/ContentGator_Runtime_content_aggregation
 
Trying the MVC framework I see? Lovely innit? :D

I seriously love using it, nice clean code and it all makes sense!

I get that ContentGator generates a sort of archive file on the server that it then throws to the client, but what happens then? I see the this.RenderContentGator() method which I presume generates the <link> and <script> tags and stuff, but how does the path to the content look? How do you reference a CSS file in an archive from a webpage?

And I presume the this.RenderContentGator() is an extension method, or do your pages need to inherit a base class?

Anyway, continue :)
 
Trying the MVC framework I see? Lovely innit? :D

I seriously love using it, nice clean code and it all makes sense!
Absolutely! I've been using webforms since .NET v1.1 came out, and I realized a little while ago that it's taken me about that long to REALLY get to know the ins and outs of using webforms because of all the extra crap it tries to do. MVC to me is so much more straightforward, and you're always sure EXACTLY what you're doing. It's like driving stick (MVC) vs automatic.

I get that ContentGator generates a sort of archive file on the server that it then throws to the client, but what happens then? I see the this.RenderContentGator() method which I presume generates the <link> and <script> tags and stuff, but how does the path to the content look? How do you reference a CSS file in an archive from a webpage?

I'll walk through the "life cycle", so to speak:

Page rendering - Files are specified by the calling the AddContentGatorPaths() method one or more times. The paths are stored in a list in the Page.Items dictionary (WebForms) or in the ViewData object (MVC).

Rendering the HTML - Calling RenderContentGator enumerates through the list of file paths. Any paths that don't exist on the disk are ignored. They are grouped by content type so that there is a single group of files per type of content (usually just javascript and css). For each group, the file paths themselves are all put into a single string and hashed, and this becomes the identifier for the file group - I call it the "file hash". The list of paths for each group, as well as the most recent file modified date for each group is stored in the application state using the file hash. In the end, the appropriate link and script elements are created, and the href/src attributes point to a url that contains the file hash. So for example, LONGSTRINGOFCHARACTERSTHATISAFILEHASH_ContentGator.axd. I use the axd extension because it is already registered in IIS for people running IIS6, which minimizes the additional configuration.

Rendered page is sent to the client

Client (browser) requests aggregated content - Each of these is a separate request to the server. The file hash is parsed out of the url. If the files have not been modified since the client last requested, an HTTP 304 NOT MODIFIED response is sent, which tells the browser to use its cached copy, and no additional content is sent. Otherwise, if the aggregated content has already been generated, it is pulled out of the application state and served. If it needs to be generated, the file list is pulled out of the application state, and each file is opened and its contents are appended to the aggregate file. Then, based on the request and the server configuration, the aggregated file might be GZipped or Deflated before being placed in the application state and sent to the client.

And I presume the this.RenderContentGator() is an extension method, or do your pages need to inherit a base class?

Yes, I've got extension methods for Page, MasterPage (for webforms), and ViewPage and ViewMasterPage (mvc).

I realized after that the extension method thing is really more of an MVC thing than webforms - in webforms you generally use a web control, but I think this way is cleaner anyways.

So - does that properly answer your questions? :)

EDIT: If you want to see it in action, I'm it on my website-in-progress: http://new.dandoes.net/ - view source and you'll see the paths
 
Back
Top