In our multi-tenant application we have a need to customize the styles used per-tenant.
We currently plan to do so using LESS and variables in the following way on the client:
- Download dependent LESS files from server
- Call web service to get configuration object
- Form string of valid LESS with variables defined
- Use
less.js
compiler to compile LESS based on these variables and the fixed LESS files from step 1
This approach has a number of downsides:
- Clients can behave badly
- Some browsers have problems with
less.js
- Compilation takes time
We would instead like to take care of this work on the server, so that roughly speaking, this happens on the server instead:
- Client requests to download one big compiled stylesheet -
GET content/styles/{tenantName}.css
- Using
tenantName
the server fetches configuration - Using a template and the appropriate variables (maybe
string.Format
or something more sophisticated) - Server compiles LESS to CSS string
- Server returns CSS string with appropriate
Content-Type
Here are my questions:
- Is this an unusual or undesirable way to achieve said result?
- Short of setting up architecture for server-side JavaScript, how can I compile the LESS into CSS?
- What must I do in the controller action or in the route configuration to make the client think that the server is returning a regular old CSS file, complete with cache control, not modified?