YUIC压缩器或类似的PHP? [英] YUICompressor or similar in PHP?
问题描述
我一直在我的测试服务器上使用yuicompressor.jar来实时更改已更改的JavaScript文件。既然我已将网站部署到公共服务器,我注意到服务器的策略禁止使用exec()或其等价物,所以不再为我执行java。
I've been using yuicompressor.jar on my test server for on-the-fly minimisation of changed JavaScript files. Now that I have deployed the website to the public server, I noticed that the server's policies forbid the use of exec() or its equivalents, so no more java execution for me.
用PHP实现了一个不错的即时JS压缩器吗?我能找到的唯一类似的东西是Minify,但它更像是一个带有缓存和一切的全面压缩解决方案。我想保持文件分离并使最小化文件遵循我自己的命名约定,因此Minify对于此目的来说有点过于复杂。
Is there a decent on-the-fly JS compressor implemented in PHP? The only thing resembling this that I was able to find was Minify, but it's more of a full-blown compression solution with cache and everything. I want to keep the files separate and have the minimised files follow my own naming conventions, so Minify is a bit too complex for this purpose.
该工具,如yuicompressor,应该能够使用文件名或JavaScript作为输入,并应该写入文件或输出压缩的JavaScript。
The tool, like yuicompressor, should be able to take either a filename or JavaScript as input and should either write to a file or output the compressed JavaScript.
编辑:澄清一下,我正在寻找不必作为独立使用的东西(即它可以从函数调用,而不是嗅探我的GET变量)。如果我只想要一台压缩机,Minify显然是一个不错的选择。
To clarify, I'm looking for something that does not have to be used as a standalone (i.e. it can be called from a function, rather than sniffing my GET variables). If I just wanted a compressor, Minify would obviously be a good choice.
EDIT2:自从我提出这个问题以来的五年里,情况发生了很大变化。今天我强烈建议将前端工作流程与服务器代码分开。有很多很好的JS开发工具,除了最简单的jQuery增强功能之外,最好有一个完整的工作流程,自动捆绑,测试和linting,只需部署缩小的捆绑包而不是原始文件。
A lot has changed in the five years since I asked this question. Today I would strongly recommend separating the front-end workflow from the server code. There are plenty of good tools for JS development around and except for the most trivial jQuery enhancements it's a better idea to have a full workflow with automated bundling, testing and linting in place and just deploy the minified bundles rather than the raw files.
推荐答案
是的,它被称为缩小。
在复杂性方面唯一需要担心的是设置组 ,它真的没什么。如果您想在一个< script>
或< link>
中添加多个JS / CSS,请编辑groupsConfig.php文件声明:
The only thing in to worry about in the way of complexity is setting up a group, and there's really nothing to it. Edit the groupsConfig.php file if you want multiple JS/CSS in one <script>
or <link>
statement:
return array(
'js-common' => array('//js/jquery/jquery-1.3.2.min.js', '//js/common.js', '//js/visuals.js',
'//js/jquery/facebox.js'),
'css-common' => array('//css/main.css', '//css/layout.css','//css/facebox.css')
);
要包含上述'js-common'组,请执行以下操作:
To include the above 'js-common' group, do this:
<script type="text/javascript" src="/min/g=js-common"></script>
这篇关于YUIC压缩器或类似的PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!