Project DescriptionContentGator 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 with GZip or Deflate compression.
Overview
- Decreases 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
WebForms and MVC
ContentGator works the same in both WebForms and MVC, so there are no differences in setup or usage between the two. The only difference is that MVC requires referencing the DanDoesDotNet.ContentGator.Mvc.dll library in addition to DanDoesDotNet.ContentGator.dll.
Required References
ASP.NET WebForms:
- DanDoesDotNet.ContentGator.dll
ASP.NET MVC Beta Preview 5
- System.Web.Mvc.dll (not included)
- DanDoesDotNet.ContentGator.dll
- DanDoesDotNet.ContentGator.Mvc.dll
Setup
Web.config (IIS6/Cassini):
<system.web>
<pages>
<namespaces>
<add namespace="DanDoesDotNet.Web.UI"/>
</namespaces>
</pages>
<httpHandlers>
<remove verb="*" path="*_ContentGator.axd" />
<add verb="*" path="*_ContentGator.axd" type="DanDoesDotNet.Web.ContentGatorHandler, DanDoesDotNet.ContentGator" validate="false"/>
</httpHandlers>
</system.web>
Web.config (IIS7):
<system.web>
<pages>
<namespaces>
<add namespace="DanDoesDotNet.Web.UI"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<handlers>
<remove name="ContentGatorHandler"/>
<add name="ContentGatorHandler" verb="GET,HEAD" path="*_ContentGator.axd" preCondition="integratedMode"
type="DanDoesDotNet.Web.ContentGatorHandler, DanDoesDotNet.ContentGator"/>
</handlers>
</system.webServer>
Usage
Using Master Pages:In Master Page:
<head>
<title>This Is a Master Page!</title>
<% this.AddContentGatorPaths(
"~/Content/_reset.css",
"~/Content/Site.css",
"~/Content/jquery-1.2.6.min.js",
"~/Content/jquery-ui.core.min.js"); %>
<asp:ContentPlaceHolder id="head" runat="server" />
<%= this.RenderContentGator() %>
</head>
In Child Page:
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
<% this.AddContentGatorPaths("~/Content/Default.css"); %>
</asp:Content>
Not Using Master Pages:
<head>
<title>This Is a Non-Master Page</title>
<%= this.RenderContentGator(
"~/Content/_reset.css",
"~/Content/Site.css",
"~/Content/jquery-1.2.6.min.js",
"~/Content/jquery-ui.core.min.js") %>
</head>
Other Considerations
- Requested files are not generated until they are requested. This means that page requests served to spiders and other non-browser clients will not result in any potential additional overhead.
- Aggregated files, once generated, are stored in the application state.
- Compression is done at the time of generation. As such, up to three copies of each aggregated file (GZipped, Deflated and Uncompressed) may be present in the application state at once. This may be less likely in practice, since most web browsers support GZip.
- Files are aggregated in the order they are specified, which guaranties that content from one file is loaded before another. This is a requirement for situations that are sensitive to loading order, such as CSS styling and loading client script that depends on client script frameworks.
- Each unique collection of content, including the order they are specified in will resulting in an additional item being placed in the application state.
Disclaimer
- This Works On My Computer and on my website in progress.
- This has not been tested on any websites with any semblance of traffic volume.
- In other words, please use this, but do so at your own risk.
Undocumented
- Optional configuration - DanDoesDotNet.Web.Configuration.ContentGatorSection allows default settings to be overwritten, such as:
- Url format - used in the rendered html to reference aggregated files
- Use/Preference of compression - whether or not to use GZip and/or Delfate, and which one is preferred (default is GZip)
- Use of HTTP 304 Not Modified - whether or not to send an HTTP 304 response if none of the files have been modified (default is true)
- Supported content types - by default, files with the extensions .js and .css are supported.
|
|