switch($modx->event->name){
    case 'OnWebPagePrerender': 
        if (!empty($modx->resource) 
            && $modx->resource->get('cacheable') 
            && $modx->resource->get('published')
            && $modx->resource->get('searchable')
            && $modx->resource->get('richtext')
            && $modx->resource->_output != ''
        )
        {  
            $html = &$modx->resource->_output;
            $html = preg_replace('|\s+|', ' ', $html);
        }
        break;   
}