How to minify the HTML output in Magento?

How can I find the file where is the HTML output? The goal is to minify it.

Russel Thomas Asked on November 26, 2015 in Magento.
Add Comment
1 Answer(s)
Best answer

If your goal is to edit the output, then you will need to catch the response object which Magento is using to send the output. First you would need to setup a listener ” http_response_send_before”:

<!-- 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>

Then you can get and set the body in the observer:

class Packagename_Modulename_Model_Observer

{

public function alterOutput($observer)

{

$response = $observer->getResponse();

$html = $response->getBody();

//modify html here

$response->setBody($html);

}

}

The response object is called at “sendResponse” in the class located at:

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

The output itself is sent to “sendResponse” and “outputBody” methods at:

MagentoInstallFolder/lib/Zend/Controller/Response/Abstract.php

Russel Thomas Answered on November 26, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.