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

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

问题描述

magento 中是否有可以输出所有 html 的文件?

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

我想缩小所有的 html 输出.

I want to minify all html output.

推荐答案

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

Magento uses a response object to send all output.

所有输出都被添加到这个对象中,然后它的sendResponse方法被调用.

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

如果你想改变输出,为 http_response_send_before 事件设置一个监听器

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);
    }
}

如果你有兴趣,这个事件在下面类的sendResponse方法中调用

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

并且输出本身在

lib/Zend/Controller/Response/Abstract.php   

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

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