简体   繁体   English

仅提供所需样式的CSS

[英]serve required styles only CSS

Is there a way of filtering large CSS files for the only required selectors on a page, and creating css files that contain just these selectors? 有没有一种方法可以过滤页面上仅需的选择器的大型CSS文件,并创建仅包含这些选择器的CSS文件?

Case: I have a very large CSS file that I want to filter on a per page basis, so that the file size is cut down and can be cached by mobile devices. 案例:我有一个非常大的CSS文件,我希望以每页为基础进行过滤,这样可以减小文件的大小并可以由移动设备缓存。 I was thinking along the lines of something like a server side dust me selectors tool. 我当时正在考虑类似服务器端的尘土选择器工具。

The particular project I am working on is using ASP.NET MVC. 我正在研究的特定项目正在使用ASP.NET MVC。

Thanks 谢谢

Heads up that while you might get smaller individual page loads, the overall load of browsing the site will be higher given that you're hitting the server each and every time for a new CSS file (rather than just caching a site-level CSS file once). 请注意,虽然单个页面的加载量可能会较小,但考虑到每次都要为新的CSS文件访问服务器(而不是仅缓存网站级CSS文件),浏览网站的整体负载会更高一旦)。

In addition, if you find that there are a lot of unique per-page CSS declarations, the CSS for the site may not be written very well. 另外,如果您发现每页CSS声明很多,则该站点的CSS可能写得不太好。 So the solution may be to go back and rethink the CSS structure to begin with, perhaps looking into OOCSS models: 因此,解决方案可能是回过头来重新思考CSS结构,也许是研究OOCSS模型:

http://wiki.github.com/stubbornella/oocss/ http://wiki.github.com/stubbornella/oocss/

Unfortunately, none of that answers your specific question. 不幸的是,这些都无法回答您的特定问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM