
Monday, May 17, 2010 | 0 comments
zendframework css php
As each day require more complex designs css files, if we optimize the normal application is to divide these files and load only what is needed, but this practice is penalized with increments's HTTP requests.
Ideally, CSS will divide into as many files as you need to optimize, but have a system that once loaded.
With Zend Framework and inform the css helpers we want and discover our exclusive special html code generates all together and orderly, saw this and works to integrate with Minify as ICS Design, I decide to upgrade a previous code I had.
I think, Minify is too heavy for what little we need, my idea is to unite all the css needed in a single file, save it in cache and go use it, as the number of combinations that use our programs is finite, once generated the file, and you need not regenerate, unless it forces. Compress the files I see a fool, and that such work can do better Apache module and Deflate.
<IfModule mod_deflate.c>SetOutputFilter DEFLATEAddOutputFilterByType DEFLATE text/cssAddOutputFilterByType DEFLATE application/x-javascript</IfModule>
Partiendo como base del código de CS Desing:
<?phpclassValclip_View_Helper_MinStyleSheetsextendsZend_View_Helper_HeadLink{publicfunctionminStyleSheets(){$items=array();$stylesheets=array();foreach($thisas$item){if($item->type=='text/css'&&$item->conditionalStylesheet===false){$stylesheets[$item->media][]=$item->href;}else{$items[]=$this->itemToString($item);}}foreach($stylesheetsas$media=>$styles){$item=newstdClass();$item->rel='stylesheet';$item->type='text/css';$newname='css_'.md5('vcss'.implode(',', $styles)).'.css';$this->process($styles, $newname);$item->href=$this->getMinUrl().'/'. $newname;$item->media=$media;$item->conditionalStylesheet=false;$items[]=$this->itemToString($item);}returnimplode($this->_escape($this->getSeparator()), $items);}protectedfunctionprocess($files, $name){$cacheFile=BASE_PATH. $this->getMinUrl().'/'. $name;if(file_exists($cacheFile)){return;}$cache='';foreach($filesas$v){$cache.=file_get_contents(BASE_PATH. $v). ">PHP_EOL; } $fp = @fopen($cacheFile, "wb"); if ($fp) { fwrite($fp, $cache); fclose($fp); } } public function getMinUrl() { return '/public/tmp/cache'; } }
Only you have to play the getMinUrl method (), since it is particular to my system and instead of:
and change:
<?phpecho$this->headLink();?>
with this other
<?phpecho$this->MinStyleSheets();?>
I think it easy deployment and does its job, one thing you can not use the @import clausule in CSS files. And the JavaScript in the next article.
No comments for this article.
Feel free to write whatever you want that is related to the article.

+34 677 62.74.00