Home php教程 PHP开发 Bootstrap“减肥”优化攻略

Bootstrap“减肥”优化攻略

Jun 07, 2016 pm 05:22 PM
bootstrap css min nbsp quot

前面的例子,我们使用 Bootstrap快速轻松地布局了一个站点。人的能力越大,其责任也就越大,而Bootstrap的情况是,功能强大,体积庸肿,这就给网页的加载带来了一点影响了,世界本来就没有完美的事物,我们不能怪Bootstrap。我们要做的是尽可能地对Bootstrap进行优化。

如何对Bootstrap的体积进行优化?下面我就谈一下我的使用心得吧。


网站制作阶段如何使用bootstrap.css样式文件

bootstrap有bootstrap.css和bootstrap.min.css两个样式文件,它们的功能是一样的。bootstrap.css样式文件是没有经过压缩的,体积虽然有点大,但代码整洁易于查看。bootstrap.min.css体积虽小,但源码只有机器才能看得懂。在设计网站时,最好选用bootstrap.css,以方便查看源码。当然,你也可以使用bootstrap.min.css查阅文档快速地完成网站的制作,这样的结果,你只能做bootstrap的门外汉,bootstrap的精髓你恐怕是无福消受了。所以,在设计网页时不要仅仅查看文档弄明白bootstrap.css中的class或者id的功能就了事,不妨打开bootstrap.css去查看一下其源码,看看它到底是如何实现的。

入门bootstrap.css,文档要看,源码也不能错过。


网站上线阶段如何优化bootstrap.css样式文件

这时,想必你已经完成了网站的制作了,正在考滤如何给bootstrap.css文件减肥了,毫无疑问直接选择压缩的bootstrap.min.css上传到你的服务器。值得庆兴的是,Bootstrap 中文网 为 Bootstrap 专门构建了自己的免费 CDN 加速服务。基于国内云厂商的 CDN 服务,访问速度更快、加速效果更明显、没有速度和带宽限制、永久免费。Bootstrap 中文网还对大量的前端开源工具库提供了 CDN 加速服务。

这样,我们又多了一个选择,把下面的链接直接放到你的网页就可以了。

<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Copy after login

进一步优化bootstrap.css

在你熟知bootstrap.css的功能模块后,你还可以根据你个人需求进行定制下载,如何定制请点击这里。

Bootstrap“减肥”优化攻略

更进一步说,如果你懂得灵活运用bootstrap.css的组件,并且能看懂bootstrap.css的源码,这时,你可以大刀阔斧地精简bootstrap.css的源码了。我在布局网志主博客时也就只用到了bootstrap.css几种布局中的一种。


小结:bootstrap.css文件的大小为129KB,压缩成bootstrap.min.css后为106KB,所以真的不算大,前面我说它体积有点庸肿,你不必放在心上,因为它对网页加载产生的影响小到可以忽略,何况Bootstrap官方还提供了加速器。

精简代码,精中求精,是一种好习惯。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? Apr 05, 2025 pm 10:33 PM

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

How to select a child element with the first class name item through CSS? How to select a child element with the first class name item through CSS? Apr 05, 2025 pm 11:24 PM

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...

Does H5 page production require continuous maintenance? Does H5 page production require continuous maintenance? Apr 05, 2025 pm 11:27 PM

The H5 page needs to be maintained continuously, because of factors such as code vulnerabilities, browser compatibility, performance optimization, security updates and user experience improvements. Effective maintenance methods include establishing a complete testing system, using version control tools, regularly monitoring page performance, collecting user feedback and formulating maintenance plans.

How to compatible with multi-line overflow omission on mobile terminal? How to compatible with multi-line overflow omission on mobile terminal? Apr 05, 2025 pm 10:36 PM

Compatibility issues of multi-row overflow on mobile terminal omitted on different devices When developing mobile applications using Vue 2.0, you often encounter the need to overflow text...

How to efficiently modify the style of nested DIV elements? How to efficiently modify the style of nested DIV elements? Apr 05, 2025 pm 10:45 PM

In-depth discussion on nested DIV style modification methods This article will explain in detail how to effectively modify the DIV element style of nested structures. The challenge we face is how...

What are the advantages of H5 page production What are the advantages of H5 page production Apr 05, 2025 pm 11:48 PM

The advantages of H5 page production include: lightweight experience, fast loading speed, and improving user retention. Cross-platform compatibility, no need to adapt to different platforms, improving development efficiency. Flexibility and dynamic updates, no audit required, making it easier to modify and update content. Cost-effective, lower development costs than native apps.

Why does negative margins not take effect in some cases? How to solve this problem? Why does negative margins not take effect in some cases? How to solve this problem? Apr 05, 2025 pm 10:18 PM

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

What application scenarios are suitable for H5 page production What application scenarios are suitable for H5 page production Apr 05, 2025 pm 11:36 PM

H5 (HTML5) is suitable for lightweight applications, such as marketing campaign pages, product display pages and corporate promotion micro-websites. Its advantages lie in cross-platformity and rich interactivity, but its limitations lie in complex interactions and animations, local resource access and offline capabilities.

See all articles