Magento:缩小HTML输出? [英] Magento: Minify HTML Output?

查看:70
本文介绍了Magento:缩小HTML输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想缩小所有html输出。

解决方案

Magento使用响应对象来发送所有输出。



所有输出都添加到此对象中,调用 sendResponse 方法。

如果您想要更改输出,请为 http_response_send_before 事件设置一个侦听器

 <! - 在你的模块的config.xml中 - > 
< http_response_send_before>
<观察者>
< unique_name>
< type>单身< / type>
< class> group / observer< / class>
< method> alterOutput< / method>
< / unique_name>
< /观察员>
< / http_response_send_before>

然后在您的观察者中您可以获取并设置身体

  class Packagename_Modulename_Model_Observer 
{
public function alterOutput($ observer)
{
$ response = $ observer->的GetResponse();
$ html = $ response-> getBody();
//在这里修改html
$ response-> setBody($ html);


code


$ b

如果你有兴趣,以下类的 sendResponse 方法

  app / code / core / Mage / Core / Controller / Response / Http.php 

并且输出本身以 sendResponse outputBody

的方法

  lib / Zend / Controller / Response / Abstract.php 


Is there any file in magento where all html will be output?

I want to minify all html output.

解决方案

Magento uses a response object to send all output.

All output is added to this object, and then its sendResponse method is called.

If you want to alter the output, setup a listener for the http_response_send_before event

<!-- in your module's config.xml -->
<http_response_send_before>
    <observers>
        <unique_name>
            <type>singleton</type>
            <class>group/observer</class>
            <method>alterOutput</method>
        </unique_name>
    </observers>
</http_response_send_before>

And then in your observer you may get and set the body

class Packagename_Modulename_Model_Observer
{
    public function alterOutput($observer)
    {
        $response = $observer->getResponse();       
        $html     = $response->getBody();           
        //modify html here          
        $response->setBody($html);
    }
}

If you're interested, this event is called in the sendResponse method of the following class

app/code/core/Mage/Core/Controller/Response/Http.php

and the output itself is sent in the sendResponse and outputBody methods of

lib/Zend/Controller/Response/Abstract.php   

这篇关于Magento:缩小HTML输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆