简体   繁体   English

CSS合并器出现问题?

[英]problems with css combiner?

I am working with a custom framework. 我正在使用自定义框架。

When I design my sites I split the CSS rules into several files eg 在设计网站时,我将CSS规则分为几个文件,例如

  • typography.css 排版
  • links.css links.css
  • master.css master.css
  • tables.css table.css
  • etc 等等

Now the obvious issue with this is that it means several http requests. 现在明显的问题是这意味着几个http请求。

As I mentioned I am working with a custom framework. 正如我提到的,我正在使用自定义框架。
In this framework to include a css file you simply call 在此框架中,您只需调用一个css文件

echo load::css('name');  
echo load::css('another');

which will spit out 会吐出来

<link rel="stylesheet" type="text/css" href="http://site.com/name.css">
<link rel="stylesheet" type="text/css" href="http://site.com/another.css">

Now what I am thinking of doing is calling 现在我想做的是打电话

load::css('name');
echo load::css('another');

as you can see i only call echo on the last one, this will output 如您所见,我仅在最后一个调用回声,这将输出

<link rel="stylesheet" type="text/css" href="http://site.com/combined/0df4899f90fe7be26f4893b1a4a30eb6.css">

0df4899f90fe7be26f4893b1a4a30eb6 == 'name another' 0df4899f90fe7be26f4893b1a4a30eb6 =='命名另一个'

So basically, 所以基本上

when you call load:css('something') it will store the name in an array, it will return the link tag with the value of md5(implode(' ', $cssArray)) at the end of the php scripts processing it will then actually create the combined file with the md5'd name (if it does not exist). 当您调用load:css('something') ,它将名称存储在一个数组中,它将在处理它的php脚本的末尾返回值为md5(implode(' ', $cssArray))的链接标记然后会实际创建带有md5名称的组合文件(如果不存在)。

This means that only one request is made to the server for all the css content. 这意味着仅对服务器发出所有CSS内容的请求。

Can anyone see any potential issues with this approach? 有人可以看到这种方法有任何潜在问题吗?
I am also planning on implementing this for javascript files. 我还计划为javascript文件实现此功能。
Could I run into any problems if I was to also implement a css/js compressor? 如果我也要实现css / js压缩器,是否会遇到任何问题?


Google Minify? Google Minify?
After doing some research I have come across google minify. 经过一些研究,我遇到了谷歌缩小。

Would it be possible to alter this so that you can just give it an array of css file paths and have it spit the contents out so that I could call something like 是否有可能改变它,以便您可以给它一个css文件路径数组并将其吐出内容,以便我可以调用类似

$css = minify::css($cssArray) Then do what I want with the minified contents? $css = minify::css($cssArray)那么我要用缩小的内容做什么?

One of the useful things I saw is the ability for it to rewrite paths? 我看到的有用的东西之一是它具有重写路径的能力吗?

Well, it might depend on how you are combining the stylesheets. 好吧,这可能取决于您如何组合样式表。 I'm not sure how your framework combines the CSS files (by name, by folder, or manually), but browsers (I dunno about IE) interpret every single line literally, even if it is redundant: 我不确定您的框架如何组合CSS文件(按名称,按文件夹或手动),但是浏览器(我对IE不了解)会逐字解释每行,即使这是多余的:

#foo
{
  color: red;
  color: green;
  color: blue; /* This one will be the actual color of #foo */
}

All of these are executed, so the last one to be interpreted is the one rendered. 所有这些都已执行,因此要解释的最后一个是渲染的。 If you re-define styles within different stylesheets (I usually use globals.css , header.css , and body.css ), the last one will take effect, which might make your site look funky. 如果重新定义了不同的样式表中的样式(我一般用globals.cssheader.cssbody.css ),最后一个会生效,这可能使您的网站看起来时髦。

I think this same concept applies to JavaScript, but I haven't encountered function re-definitions yet. 我认为同样的概念也适用于JavaScript,但是我还没有遇到函数重新定义的问题。

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

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