Categories
General

Twitter Bootstrap, LESS CSS, and Caching Problem

I'm working on some works right now with a small team at the office. We decided to use as the front-end . We came up with this solution for some key reasons:

  • We need to do it fast.
  • It's easy to maintain, especially for a collaborative project
  • Bootstrap is cool.

There are lots of similar frameworks to choose like Skeleton, 960.gs, Blueprint, Foundation, and more. It didn't take long discussion to take Bootstrap. Its and flexibilities are just perfect for our need. The next thing is that we need to do some customisations, for example on the sizes and colours. Since Bootstrap might updates in the future, it's better to leave the core files untouched.

LESS

Basically, it's easy to customise them by using its own customisation tool. But, I prefer another method by using LESS. And yes, Bootstrap works great with LESS. The works straight forward. After downloading less.js , add these two lines in the

 

Inside bootstrap.less file, there is a little note that we can easily modify the font color and size by working on the variables. file. I decided not to edit it. I created another .less file — for example: mycustom.less — and import it from bootstrap.less file. So, my bootstrap.less file looks like this:

...
@import "accordion.less";
@import "carousel.less";
@import "hero-unit.less";
// My Custom LESS
@import "mycustom.less";
...

And, this is what I have for mycustom.less:

@baseFontSize: 13px;
@tableBorder: #ddd;
@navbarInverseBackground: #faa141;
@navbarInverseBackgroundHighlight: #ec8b22;
@navbarInverseBorder: #d77c1b;
@navbarInverseLinkColor: #fff;

It should just work. But, does it work as expected? No.

Caching

Editing and saving mycustom.less file, and refreshing my page does not load the latest variables. It takes time to refresh/load the latest changes. It's not good. It happens because less.js caches the .less files called using @import.
I tried to modify the web setting by adding these lines in my httpd.conf file:


Header set Cache-Control "no-cache"

But, it didn't work. After searching for solutions, there is a method offered for this issue. I added this line of code:

Now, whenever I make some changes on my .less files, reloading the page will give the latest changes. It works.

2 replies on “Twitter Bootstrap, LESS CSS, and Caching Problem”