css最佳实践 - 将所有css组合到单个样式表中? [英] css best practices - combining all css into a single stylesheet?
问题描述
我在某处阅读 -
您应该将所有CSS(文件)放入一个样式表
You should put all CSS (files) into one single stylesheet
问题 -
1)这是好的做法吗?如果是的话,为什么?
1) Is it good practice? if yes, then why?
推荐答案
您应该将所有的CSS合并到一个文件, 。
You should combine all your CSS into one file to reduce the amount of requests made to your server.
类似的主题是 sprite sheets
,将多个图片组合成一个大图片,以减少对您的服务器发出的请求数量。
A similar topic is sprite sheets
, the combination of multiple images into one large image to also reduce the amount of requests made to your server.
您会发现加载100x 5kb文件比加载单个500kb文件要慢得多。
You'll find that loading 100x 5kb files is a lot slower than loading a single 500kb file.
准备将文件上传到实时环境,还应考虑压缩CSS和JavaScript文件。这里有大量的在线工具,例如:
When you're ready to upload your files to a live environment, you should also consider compressing your CSS and JavaScript files. There are a vast amount of online tools for this, eg:
- CSS Compressor.
- JavaScript Compressor.
- HTML Compressor.
这篇关于css最佳实践 - 将所有css组合到单个样式表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!