"finish" event should do it. Sometime ago I wrote a module that compresses HTML by removing all extra whitespace, I'm attaching it here - maybe you will find it useful. It was working on a very simple website. For real-live app you may want to for example check content-type header, to ensure it won't compress things like JSON.
namespace HtmlCompressor class Module { /** * found somewhere on stack overflow */ private function compress($html) { preg_match_all('!(<(?:code|pre|script).*>[^<]+</(?:code|pre|script)>)!',$html,$pre); $html = preg_replace('!<(?:code|pre).*>[^<]+</(?:code|pre)>!', '#pre#', $html); $html = preg_replace('#<!–[^\[].+–>#', '', $html); $html = preg_replace('/[\r\n\t]+/', ' ', $html); $html = preg_replace('/>[\s]+</', '><', $html); $html = preg_replace('/[\s]+/', ' ', $html); if (!empty($pre[0])) { foreach ($pre[0] as $tag) { $html = preg_replace('!#pre#!', $tag, $html,1); } } return $html; } public function compressHtml(MvcEvent $e) { $response = $e->getResponse(); // compress HTML output $response->setContent($this->compress($response->getContent())); } public function onBootstrap(MvcEvent $e) { $app = $e->getApplication(); $sm = $app->getServiceManager(); $eventManager = $app->getEventManager(); $eventManager->getSharedManager()->attach('Zend\Mvc\Application', 'finish', array($this, 'compressHtml'), 1002); } } -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/ZF2-How-to-clear-the-contents-of-the-html-from-blank-lines-tp4661474p4661476.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com