简体   繁体   English

PHP CSS / JS缩小程序?

[英]php css/js minifier?

I have a custom loader for my css and javascript functions. 我有一个用于CSS和javascript函数的自定义加载程序。

as such. 因此。

when I am ready I have a list of css and another of javascript files. 当我准备好时,我有一个CSS列表和另一个javascript文件。

I am looking for a way that I can then call a function and it will output a path to a compressed and combined css and js file. 我正在寻找一种方法,然后我可以调用一个函数,它将输出压缩和组合的css和js文件的路径。

so. 所以。

something like 就像是

load::css('master');
load::css('links');
load::css('buttons');
load::css();

(calling load:css() without any params should generate the minified css link) (调用不带任何参数的load:css()应该会生成缩小的CSS链接)

What classes do you suggest for doing this? 您建议做什么课程?

它不能完全按照您想要的方式工作,但是我发现使用minify(http://code.google.com/p/minify/)非常有用,然后使用一个单独的类(我使用Zend Framework的headStyle查看助手)收集我需要的所有css文件,然后构建一个我包含的css / JS链接。

I wrote a "build" shell script for javascript and css, which I the javascript from the server, and then compress it using YUICompressor. 我为javascript和css编写了一个“ build” shell脚本,我从服务器上获取了javascript,然后使用YUICompressor对其进行了压缩。

This wouldn't be a run-time compression like you're looking for, it'd be more of a one-time build process you do when you publish your site. 这并不是您所需要的运行时压缩,而是您发布站点时要做的一次性构建过程。 My javascript is mostly static, though, so I can get away with this. 我的JavaScript大部分是静态的,所以我可以摆脱它。

#!/bin/bash
cd /webroot/js
wget -nc -O filename.premin.js http://localhost/js/filename.src.js
java -jar yuicompressor.jar --line-break=200 -o filename.min.js filename.src.js
rm filename.premin.js

If I understood your aim correctly Php Speedy may help you. 如果我正确理解了您的目标,Php Speedy可能会为您提供帮助。 Check it out: http://aciddrop.com/php-speedy/ . 检查一下: http : //aciddrop.com/php-speedy/

It sounds like the problem you're trying to solve is that you have "too many" JS/CSS files being served. 听起来您要解决的问题是正在提供“太多”的JS / CSS文件。

By looking for a way to merge them together, you're only compounding your problem by inventing new files that must be delivered to your clients. 通过寻找一种将它们合并在一起的方法,您只会通过发明必须交付给客户的新文件而使问题更加复杂。

Instead, learn about HTTP caching, and use it: http://www.mnot.net/cache_docs/ 相反,请学习HTTP缓存,并使用它: http : //www.mnot.net/cache_docs/

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

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