Horje

How to minify all html code of Your Website

Put following code very top of your site.

index.php
Example: PHP
<?php

function sanitize_output($buffer) {

    $search = array(
        '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
        '/[^\S ]+\</s',     // strip whitespaces before tags, except space
        '/(\s)+/s',         // shorten multiple whitespace sequences
        '/<!--(.|\s)*?-->/' // Remove HTML comments
    );

    $replace = array(
        '>',
        '<',
        '\\1',
        ''
    );

    $buffer = preg_replace($search, $replace, $buffer);

    return $buffer;
}

ob_start("sanitize_output");

?>

Output should be:

How to minify all html code of Your Website



Single Articles
How to minify all html code of Your WebsitePHP Cache Tutorial
How to minify html code of Your WebsitePHP Cache Tutorial
How to make short all codes of your websitePHP Cache Tutorial


Related Articles
How to create PHP Simple HTML Cache for a Web Page PHP Cache Tutorial
How to minify all code of Your Website PHP Cache Tutorial

Type:
Php
Category:
Web Tutorial
Sub Category:
PHP Cache Tutorial
Uploaded by:
Admin



Share on: