/** * Minify an HTML string * @param {str} $html * @return {str} minify $html */ private static function _minifyHtml($html) { if (empty($html)) { throw new Exception('Parameter [$html] is empty'); } $options = array('optimizationLevel' => 1); return HTMLMinify::minify($html, $options); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // @todo check if not authentified instead of editing if ($request->cookie('pressEditing')) { PressFacade::setEditing(); return $next($request); } // The cache is automatically served by the webserver. So if // we hit this code, the only thing to do is to save the // response in an .html file // the generated output MUST NOT have user-based content. It // must be the same content for everybody // PressFacade::skipCache() can be used to not cache the // current request $response = $next($request); if (!PressFacade::isCacheableRequest($request, $response)) { return $response; } $contentHTML = $response->getContent(); $miniContent = HTMLMinify::minify($contentHTML, ['doctype' => HTMLMinify::DOCTYPE_HTML5]); $cache = PressFacade::cache(); $cache->writeFile($miniContent); return $this->makeFakeResponse($miniContent); }
public function process($str) { return HTMLMinify::minify($str); }
* it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Primary Author Contact: Jacob Bates <*****@*****.**> */ require '../vendor/autoload.php'; use zz\Html\HTMLMinify; ini_set('max_execution_time', 300); $pdf = new mPDF(); $stylesheet = <<<EOD <link rel="stylesheet" href="../assets/css/pdf.css" type="text/css"> EOD; session_start(); $title = $_POST['context_title']; session_write_close(); $html = HTMLMinify::minify($_POST['result_html']); $pdf->SetHeader("Scanned on " . date("m/d/Y") . " at " . date("g:i a")); $pdf->SetFooter("Page {PAGENO} / {nb}"); $pdf->WriteHTML($stylesheet, 1); $pdf->WriteHTML($html, 2); $pdf->Output($title . '_' . date("Y-m-d_g:i-a") . '.pdf', 'D'); exit;
function minify_html($output) { $minify = new HTMLMinify($output, array('optimizationLevel' => HTMLMinify::OPTIMIZATION_ADVANCED)); return $minify->process(); }
public function testAttributeQuoted() { $source = '<img id=id class=\'class\' src="img.png" title />'; $expect = '<img id=id class=\'class\' src="img.png" title />'; $actual = HTMLMinify::minify($source); $this->assertEquals($expect, $actual); }
/** * Uploads the fixed course syllabus * @param string $corrected_error - The html that has been fixed * @param string $error_html - The html to be fixed */ public function uploadFixedSyllabus($corrected_error, $error_html) { $get_uri = $this->base_uri . "/api/v1/courses/" . $this->course_id . "/?include[]=syllabus_body&access_token=" . $this->api_key; $content = Request::get($get_uri)->send(); $html = $content->body->syllabus_body; $error_html = HTMLMinify::minify(str_replace($this->annoying_entities, $this->entity_replacements, $error_html), ['doctype' => 'html5']); $corrected_error = HTMLMinify::minify(str_replace($this->annoying_entities, $this->entity_replacements, $corrected_error), ['doctype' => 'html5']); $html = HTMLMinify::minify(str_replace($this->annoying_entities, $this->entity_replacements, htmlentities($html)), ['doctype' => 'html5']); $html = str_replace($error_html, $corrected_error, html_entity_decode($html)); $put_uri = $this->base_uri . "/api/v1/courses/" . $this->course_id . "/?&access_token=" . $this->api_key; Request::put($put_uri)->body(['course[syllabus_body]' => $html])->sendsType(\Httpful\Mime::FORM)->send(); }
/** * Minify HTML. * * @param Result $result * * @return Result */ public function execute(Result $result) { $result->setData(HTMLMinify::minify($result->getData(), array('optimizationLevel' => HTMLMinify::OPTIMIZATION_ADVANCED))); return $result; }
/** * Handle Caching and Minification * * @todo Add logging. * * @mehod cache * @author potanin@UD * * @param $buffer * * @return mixed|void */ public function ob_start(&$buffer) { global $post, $wp_query; // @note thro exception to abort rest of ob_start from a filter. try { $buffer = apply_filters('wp-pagespeed:ob_start', $buffer, $this); } catch (\Exception $e) { return $buffer; } // Media Domain Sharding. if ($this->get('minify.enabled')) { $buffer = HTMLMinify::minify($buffer, array('optimizationLevel' => 'OPTIMIZATION_ADVANCED', 'emptyElementAddWhitespaceBeforeSlash' => true, 'emptyElementAddSlash' => false, 'removeComment' => true)); } // Never cached logged in users. if (function_exists('is_user_logged_in') && is_user_logged_in()) { return $buffer; } // Ignore CRON requests. if (isset($_GET['doing_wp_cron']) && $_GET['doing_wp_cron']) { return $buffer; } // Do not cache search results. if (is_search()) { return $buffer; } // Ignore 404 pages. if (is_404()) { return $buffer; } // Bail on Media and Assets. if (is_attachment()) { return $buffer; } // Bypass non-get requests. if ($_SERVER['REQUEST_METHOD'] !== 'GET') { return $buffer; } // Always bypass AJAX and CRON Requests. if (defined('DOING_CRON') && DOING_CRON && (defined('DOING_AJAX') && DOING_AJAX)) { return $buffer; } return $buffer; }