Html 一次调用多个外部css文件到html页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17432929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
calling multiple external css files at once to html page
提问by Digital site
I was wondering how I can call multiple external css files at once instead of calling each individually. I want to do that to avoid the request number and minimize it to one per multiple external css files.
我想知道如何一次调用多个外部 css 文件而不是单独调用每个文件。我想这样做是为了避免请求编号并将其最小化为每个多个外部 css 文件一个。
I tired the following, but didn't work!!
我累了以下,但没有工作!
<link rel="stylesheet" href=" http://statics.mydomain.co/style.css,functionstyle.css,widgets.css,edges.css,options.css,tags.css" type="text/css">
I thought it is a lot easier than that!!
我认为这比那容易得多!!
any idea what I'm missing here!!!
知道我在这里错过了什么!!!
采纳答案by Dan Grahn
Two options.
两种选择。
1. Css @import
1. CSS @import
@import url(stylesheet.css);
See documentation.
请参阅文档。
NOTE!: The browser actually does make multiple calls here, it is just hidden from the HTML
注意!:浏览器实际上确实在这里进行了多次调用,它只是从 HTML 中隐藏了
2. PHP
2. PHP
Use minifyto shrink, cache, and combine your CSS/JS files.
使用minify来缩小、缓存和组合您的 CSS/JS 文件。
Here is a minify tutorial
这是一个缩小教程
Here is a list of more compression tools.
回答by kalley
回答by Atrox111
Even if you can minimize your html code to only one line, the client has to load them all individually 'cause they still are in different files on the server.
即使您可以将 html 代码最小化为一行,客户端也必须单独加载它们,因为它们仍然位于服务器上的不同文件中。
If you want to combine the Styles into one file just do it manually or on server-side.
如果您想将样式组合到一个文件中,只需手动或在服务器端进行。
Furthermore you could minify your CSS with an online tool to make the file's size smaller.
此外,您可以使用在线工具缩小 CSS 以缩小文件大小。
回答by Marc Audet
Once you have sorted out all the CSS rules and you are ready to go into production, you should combine all your CSS files into a single file and then minify it.
一旦您整理了所有 CSS 规则并准备投入生产,您应该将所有 CSS 文件合并到一个文件中,然后将其缩小。
You can then link to a single file from your pages.
然后,您可以从您的页面链接到单个文件。
As a start, read the previous question, it has some useful references:
首先,阅读上一个问题,它有一些有用的参考:
回答by Pevara
You can use the @import
statement inside your 'master' css, to make it include multiple files at once. All you would have to do is link to your one master file in your HTML.
您可以@import
在“主”css 中使用该语句,使其一次包含多个文件。您所要做的就是链接到您的 HTML 中的一个主文件。
However, this will not limit your requests. As long as they are separate files, you will have to do separate requests.
但是,这不会限制您的请求。只要它们是单独的文件,您就必须进行单独的请求。
For real performance improvement you would have to merge the files into one bigger file. There are some good tools out there. I prefer LESS, which is a precompiler that does lots more, but can also merge multiple files into one (minified) master css
为了真正提高性能,您必须将这些文件合并为一个更大的文件。那里有一些很好的工具。我更喜欢LESS,这是一个可以做更多事情的预编译器,但也可以将多个文件合并到一个(缩小的)主 css 中