我想压缩我的html/js代码,当我得到响应从前端控制器在zend或之前的内容发送到客户端。
当我在view source
中查看此代码时,它显示所有带有空格的代码,而不像在Google中。
有没有办法做到这一点
你可以创建一个在dispatchLoopShutdown期间运行的插件,从那里你可以获得响应的主体,操作它,然后在最小化它后设置主体。
下面是一个例子:
<?php
class Application_Plugin_ShrinkSource extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
// get the output that will be sent to the client
$body = $this->getResponse()->getBody();
// remove extra whitespace, and other cleanup
$body = someFunctionToRemoveWhitespace($body)
// set the modified content back to the body
$this->getResponse()->setBody($body);
}
}
在你的引导中,你可以像
那样注册插件Zend_Controller_Front::getInstance()
->registerPlugin(new Application_Plugin_ShrinkSource());