Magento: Minify HTML Output?

前端 未结 5 875
一个人的身影
一个人的身影 2020-12-31 15:22

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

I want to minify all html output.

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 15:46

    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

    
    
        
            
                singleton
                group/observer
                alterOutput
            
        
    
    

    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   
    

提交回复
热议问题