views:

197

answers:

1

What are some unintended consequences associated with mapping an ASP.NET HTTP Handler to a static extension like *.css?

<add verb="*" path="handler.css" type="Web.HttpHandler.ThemeCssHandler" />

By default, *.css is registered as static content in applicationHost (under IIS7):

<staticContent lockAttributes="isDocFooterFileName">
    <mimeMap fileExtension=".css" mimeType="text/css" />

Aren't static requests normally handled more efficiently by IIS alone?

The key motivation is really to have dynamic CSS served under its known extension as opposed to something like *.axd (for simplicity and compatibility with OOTB cache policies); but we'd like to make sure this doesn't degrade the service of non-dynamic CSS requests.

+1  A: 

The usual way CSS files are processed is with the static file handler, so substituting your own handler has the potential of performing as well as it does. The details depend on the handler.

You can actually use the *.aspx handler for this purpose, if you want (though it takes a bit more configuration). However, one side-effect is that all dynamic content is marked with Cache-Control: private by default, which will prevent caching by proxies.

Output caching is also enabled by default for static files. If you make them dynamic, then your handler will have to enable it explicitly.

RickNZ
Thanks, Rick; on the client, the request will carry the same headers as a traditional *.css request using a custom HttpCachePolicy. What I was more concerned about was the fact that static files are typically processed by a native handler - e.g. <add name="StaticFileModule" image="%windir%\System32\inetsrv\static.dll" />. Does associating a managed handler to a static extension like *.css change the execution pipeline for all *.css requests? Also, while we haven’t confirmed this, I would imagine that the dynamic *.css continues to be eligible for kernel caching.
Nariman
Yes, handlers are assigned on the basis of file extensions, so if you set one for *.css, it will apply to all CSS files. However, the performance difference between the native handler and a managed one by itself won't be huge unless your machine is doing nothing but serving CSS files. Without special care, the big perf impact is on the caching side. Kernel caching by http.sys will still be possible (as it is for all dynamic files), but only if you have the appropriate HttpCachePolicy selected, which isn't done by default for dynamic files.
RickNZ