For a big single page web application using ASP.net, MVC5 and Angular JS I'm looking to serve dynamic generated stylesheets. The application will have an big amount of users (> 1000s) that individually can set about 10 variables. These include a few colors and logos. These colors and logos will be used in the less stylesheet to generate lots of classes/styles. The stylesheet is compiled from a lot of files, about 50 .less files.
I'm planning to use the following approach:
- On loading index.html, after user login, I call an ASP action to load the stylesheet
<link href="Give/Me/My/Dynamic/Stylesheet/For/User/12122312">
- The controller action will do its magic and gets the 10 user variables from the database
- The server will than use .dotless to compile the less to css
- Server returns string
This approach will work, but I'm afraid the performance will be not so good. My questions:
- Is dotless the fastest way to compile less?
- How long will the databasecall + compiling take?
- Is this the way other application do this?
- I'm looking if there's a way to cache the css request - maybe check if there has been a change since the last time the css was compiled.
What will not work:
- Compile the less to css and then change the variables in the css (saves a compile every time). Some of the colors in the stylesheet will be based upon on of the variables. (eg lighten(#333, 0.3) etc).
- Use a static stylesheet and then override these in the head of the HTML doc. There will be a whole lotta custom styles involved!
Some other thoughts:
This solution seems to do the same, but compiles on build:
This solution saves the variables to a static file and uses that for compiling. This saves a database call, but the directory gets crowded with lots of users.