You should be compiling your .less
files into a single .css
file and including it once on every page (i.e. styles.less
compiled to styles.css
). That way the browser doesn't have the overhead of recompiling the CSS every page load. Also the .css
file can be cached.
Instead of adding:
<link href="/css/colours.less" />
<link href="/css/styles.less" />
<link href="/css/forms.less" />
<link href="/css/widgets.less" />
...etc...
It should be:
<link href="/css/styles.css" />
And in styles.less
you should have:
@import 'colours';
@import 'forms';
@import 'widgets';
...etc...
Otherwise, if you want to reuse colours.less
in multiple .less
stylesheets, you'll need to @import
them in each stylesheet.
For development purposes, I recommend using a single, primary .less
file that contains only variable declarations and @import
statements. That way it's easy to find where additional scripts are added. LESS makes it very easy to add or remove stylesheets to keep the code organized.
For example, style.less
might look something like:
// import statements
@import 'core';
@import 'mixins';
@import 'lists';
@import 'buttons';
@import 'forms/form';
@import 'forms/search';
@import 'forms/contact-us';
@import 'modules/module';
@import 'modules/archive';
@import 'modules/events';
// variables
@image-path: '/assets/images/';
@font: Helvetica, Arial, sans-serif;
@black: #000;
@dark-grey: #333;
@grey: #888;
@light-grey: #CCC;
@white: #FFF;
@red: #F00;
This structure makes it easy to add a new stylesheet, such as when adding a new module:
...
@import 'modules/events';
@import 'modules/foo'; //add another module
...
It also makes it very easy to remove styles if they're no longer being used. If the foo
module was to be removed, it's easy to remove all the foo
styles simply by removing the @import 'modules/foo';
statement.