-
Notifications
You must be signed in to change notification settings - Fork 5
Moth handles all external CSS files. It can:
- Combine multiple files into one single request
- Minify files on the fly (via YUICompressor)
- Apply CssTidy
- Render all CSS tags at the top of the page
- Automatically expire client-side cached stylesheets on an update
You can register any script via:
<% Html.RegisterStylesheet("~/content/site.css"); %>
You can do this from any type of view: master pages, views and partials.
To render all the style tags, put the following at the top of your master page, in the <head>
tag.
<%=Html.RenderCss() %>
By default, all CSS files are grouped into one single request. This might not be the most efficient way, for example when you have site-wide stylesheets; and module-specific CSS. In this case you'll want to group your global section of CSS into one request, as it allows for client-side caching, and group the module-specific CSS into another one. For this purpose Moth supports a second parameter for the RegisterStylesheet
function.
<%
Html.RegisterStylesheet("~/content/site.css", "global");
Html.RegisterStylesheet("~/content/more.css", "global");
Html.RegisterStylesheet("~/page-specific.css");
%>
All files are grouped based on the second parameter, so in this case we'll have 2 requests.
Moth sends the requests automatically with long expire headers, so users won't have to load your resources every time. This allows for a faster loading of your pages on a recurring visit. When you update a CSS file, you will want to push the new version to your clients. Therefore Moth will automatically put a version number at the end of your requests, based on the hash of the content of all scripts. You won't have to do anything, Moth will handle this automatically.
If you have 'execute' rights on the folder where your website is running; Moth will run CssTidy on all your files. If not, Moth won't.
Moth will automatically fix all image references in your CSS files so they will match their new location. You won't have to bother about them.