开发者

Style and script management in Asp.Net MVC

I'm right now using asp.net mvc 2.0 in my projects. I like the way asp.net mvc is designed开发者_运维问答 and works, but i feel it lack good support for applications with a large amount of styles and scripts.

In order to isolate different parts of an application i use areas, child only actions and partials. I would like a standard way to separate my scripts and styles too, i.e. put my script and style files in an area (not in the script and content folder on the root) and good way of including them on pages where they belong.

Right now I'm using a content place holder on every page in which I can include any script and styles for that action, but I would like a way of including a script from e.g. child only action.

What are your thoughts on this, how do you manage your script and style files, are there any patterns or best practices?


You could use Chirpy (ehem): http://chirpy.codeplex.com/

Or SquishIt: https://github.com/jetheredge/SquishIt

Or create a controller that handles requests for js/css files: http://www.weirdlover.com/2010/05/10/zcontroller-asp-net-mvc-controller-fo-your-scripts-styles-images/

Or create an IHttpModule for handling js/css requests: How2: what event to hook in HttpModule for putting js links into head element

Not sure if that's what you're looking for. But it's all I've got.


I have used a style of registering scripts/css I first saw here. You register your scripts in code and they are then minified, mashed, cached and included in one place. I extending this approach to allow grouping of scripts. So you could include "master page" scripts in your "default" group these would be outputed on your master page. Child pages could register your own groups.

Done well it's very elegant and your get a noticable performance boost and make YSlow happy.

Cheers,


I put scripts and styles which are used on every page in the master and then leave a content placeholder so that every page has the possibility to include required scripts and styles. Exactly as you do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜