asp.net mvc - Using MVC bundling to generate custom CSS from LESS files -


i have multiclient system whereby different clients have different brand colours.

these colours stored in db , referenced throughout less files @color{1-3}.

we used maintain colors.less file reference places these colours featured. in client-neutral situation render normal bundle our brand colours within client area inject stored css file generated when client colours changed in db.

this worked fine maintaining colours.less file becoming bit unwieldy i'd render css "real time" no css file needs generated manually. can't every request because hammer server intensive css generation every page load.

my question how can use bundling or other form of caching generate css on fly (i.e without storing css files) without hammering server?

you can implement custom http handler:

public class customhandler : ihttphandler {     #region ihttphandler members      public bool isreusable     {         // return false in case managed handler cannot reused request.         // false in case have state information preserved per request.         { return true; }     }      public void processrequest(httpcontext context)     {         var sb = new stringbuilder();         // read values db , cache them httpcontext.current.cache         sb.append(".black : { color: 'black'; }");          context.response.clear();         context.response.contenttype = "text/css";         context.response.write(sb.tostring());     }      #endregion } 

web.config:

 <system.webserver>         <handlers>       <add name="colorshandler" verb="get" path="colors.axd" type="webapplication3.infrastructure.customhandler, webapplication3, version=1.0.0.0, culture=neutral" />     </handlers>   </system.webserver> 

the limitation cannot reference handler mvc bundle because mvc bundle can handle static files. have reference stylesheet:

 <link rel="stylesheet" href="~/colors.axd" type="text/css"> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -