官术网_书友最值得收藏!

Installing Less on the client side

To use Less in our code, we can download it from the Less site by browsing to http://lesscss.org/#download-options-browser-downloads and then clicking on the Download Less.js v.1.7.3 button.

Save the contents of the file, displayed in the browser window as less.min.js, in a subfolder called js, under the main lessjs project folder; you will end up with something like this screenshot (this shows the files you will create later in this chapter):

In a copy of the project.html file we created at the start of this chapter, add the code as highlighted:

<!DOCType html>
<head>
  <meta charset="utf-8">
  <title>Untitled</title>
  <link rel="stylesheet/less" type="text/css" href="css/project.less">
 <script src="js/less.min.js"></script>
</head>
<body>

That's it—once this has been added, Less will compile the styles into valid CSS dynamically and render the results in the browser. The key point to note is that for Less to compile the styles correctly, the reference to the Less style sheet file must be included in your code first, before the reference to the Less library.

Tip

Can I get the source code for Less?

If you want to delve into the Less library and examine the code in more detail, then you might like to download a copy of the uncompressed version of the library, which is available at https://github.com/less/less.js/archive/master.zip.

Using a CDN

Although we could download a copy of the library, we don't need to when hosting it in a production environment. Less is available on a content delivery network hosted by CDNJS. You can instead link to this version in your code.

If you host an international site with a lot of network traffic, using a Content Delivery Network (CDN) hosted file will help ensure that the library is downloaded to a visitor's computer from a server that is geographically close to them. This helps in making the response quicker, as the browser will use a cached version on subsequent visits to the page, which saves on bandwidth. This is not recommended for development however!

Note

If you want to use a CDN link, then it can be found at http://cdnjs.cloudflare.com/ajax/libs/less.js/1.7.3/less.min.js.

主站蜘蛛池模板: 五原县| 光山县| 博湖县| 安多县| 北川| 津市市| 乳山市| 明水县| 东乡| 耿马| 浦北县| 瑞丽市| 砀山县| 梧州市| 杭州市| 平阴县| 南华县| 大冶市| 玉山县| 昌乐县| 松潘县| 资阳市| 勐海县| 阜阳市| 青阳县| 太保市| 山丹县| 无棣县| 邳州市| 乐陵市| 娱乐| 光山县| 宜春市| 柘荣县| 宝兴县| 泾源县| 常宁市| 吉木萨尔县| 沿河| 卓尼县| 南阳市|