I’m working on some works right now with a small team at the office. We decided to use Bootstrap as the front-end development framework. 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 features and flexibilities are just perfect for our need. The next thing is that we need to do some customisations, for example on the font sizes and colours. Since Bootstrap might release 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 installation works straight forward. After downloading less.js
file, add these two lines in the <head>
<link rel="stylesheet/less" href="/path/to/bootstrap.less">
<script src="/path/to/less.js"></script>
Inside bootstrap.less
file, there is a little note that we can easily modify the font color and size by working on the variables.less 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 server setting by adding these lines in my httpd.conf
file:
<FilesMatch ".less$">
Header set Cache-Control "no-cache"
</FilesMatch>
But, it didn’t work. After searching for solutions, there is a method offered for this issue. I added this line of code:
<script>localStorage.clear(); </script>
Now, whenever I make some changes on my .less files, reloading the page will give the latest changes. It works.