如何最小化css的数量
就像 javascript 压缩器一样,我对 css 使用相同的技术。首先,我将所有文件合并为一个文件,然后压缩。但是,HTML 的行为与之前多个 css 文件的行为不同。减少 CSS 文件数量的最佳方法是什么?
Just like javascript compressor, i use the same technique for css. First, i merge all the file into a single file and then compressor. But, the behaviour of HTML is not same as earlier with multiple css file. What is the best way to minimize the the no of CSS File?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您是否以正确的顺序将它们合并到一个文件中?由于 CSS 允许覆盖较早的规则,因此您可能需要注意组合文件的哪一部分位于其他部分之前。
Are you merging them into a single file in the proper order? Since CSS allows overriding earlier rules, you may need to be careful about which portion of the combined file comes before what other portions.
检查将文件加载到合并脚本中的顺序,就像其他人提到的那样。
我发现 Sprockets 是依赖管理的好工具。它跟踪文件中的更改并输出单个文件,准备压缩。它还适用于您的 CSS 文件。
Check the order of loading you files into the merge script, like others have mentioned.
I found Sprockets to be good tool for dependency management. It keeps track of changes in your files and outputs a single file, ready for compression. It will also work with your CSS files.
确保您的 HTML 有效。如果您的浏览器处于怪异模式,则可能会使用压缩器认为不必要的 CSS。
Make sure your HTML is valid. If your browser is in quirks mode, it may be using CSS that your compressor thinks is unneccessary.
您是否可能错误地将打印样式表也合并到主样式表中? (只是猜测。)
如果是这样,并且您想保持这种方式,您仍然可以通过将其内容包含到:
Could it be, that you merge, by mistake perhaps, also your print stylesheets into the main stylesheet? (Just a guess.)
If so, and you'd like to keep it that way, you can still do that by enclosing their content into:
HTML 的行为通常不应改变。如果确实发生这种情况,我猜测您的规则相互冲突,并且这些规则相互覆盖,并且 CSS 文件没有按照与之前加载的顺序相同的顺序进行合并。
The behavior of your HTML generally should not change. If this does indeed happen, I'm guessing that you have conflicting rules that overwrite one another, and that the CSS files are not being merged in the same order as they were previously loaded.
只要CSS文件位于同一个文件夹中,它们按照在页面中加载的顺序串联,并且将生成的文件放置在与原始文件相同的文件夹中,就应该没有问题。
如果样式发生冲突,则它们的顺序很重要,因为最后指定的样式将优先。
文件的位置对于您指定的任何相对图像 URL 都很重要,因为它们是相对于 CSS 文件的,而不是相对于网页的。
As long as the CSS files are in the same folder, they are concatenated in the same order as they were loaded in the pages, and the resulting file is placed in the same folder as the original files, there should be no problem.
The order of the styles matter if they are conflicting, as the style last specified will take precedence.
The location of the files matter for any relative image URLs that you specify, as they are relative to the CSS file, not relative to the web page.