gmoothart / NCombo

Asp.Net combo handler for YUI3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NCombo

An http resource combo-loader, for requesting multiple .css or .js files in a single request. Files are cached and gzipped. Tuned and primarily intended for use with YUI 3, but could be useful in any scenarion where you want to minimize http traffic by combining text resources.

For security it will only serve files within a specified base directory (“~/yui/” by default), and it will only serve files whose names match a whitelist (*.js and *.css currently)

How to Use

NCombo is an asp.net http handler. In order to use it, you must register it in your web.config:


  <!-- for IIS 6 -->
  <system.web>
    <httpHandlers>
      ...
      <add verb="GET" path="ncombo.axd" type="NCombo.ComboHandler, NCombo" />
    </httpHandlers>
  </system.web>

  <!-- for IIS 7 -->
  <system.webServer>
    <handlers>
      ...
      <add name="ncombo" verb="GET" path="ncombo.axd" type="NCombo.ComboHandler, NCombo" />
    </handlers>
  <system.webServer>

If you use the NCombo default settings, this is all you need to do.

All files served by NCombo must be in a common root directory. The default is ~/yui/, but this can be customized with the “baseDir” configuration setting. Similarly, the cacheing directory is ~/yui/cache/ by default, but can be customized.


  <configSections>
    <section name="ncombo" type="NCombo.NComboSectionHandler,NCombo"/>
  </configSections>
  ...
  <ncombo baseDir="~/yui/" cacheDir="~/yui/cache/" />

The only thing left to do is to tell YUI about your custom combo-handler. Below is an example that configures YUI itself and a custom directory for gallery modules.


  YUI_config = {
      comboBase: '<%= Url.Content("~/ncombo.axd") %>?',
      combine: true,
      //filter: 'debug',
      groups: {
          gallery: {
              combine: true,
              root: 'gallery/build/',
              patterns: { 'gallery-': {},
                  'gallerycss-': { type: 'css'}
              }
          } // gallery
      } // groups
  };

The example project includes working examples for serving YUI 3.x itself, YUI 2in3, and custom modules like those in the gallery.

Todo

  • smarter css path fixing to save a few extra bytes.
  • think about versioning for custom modules. How to manage with more granularity?
  • Add example of non-YUI usage to the example project.
  • Make whitelist configurable

About

Asp.Net combo handler for YUI3


Languages

Language:JavaScript 99.6%Language:C# 0.4%Language:ASP 0.0%