Store PHP script output in "compressed" HTML

2

In a content manager, I usually generate static pages in HTML every time they are visited, the script re-writes HTML when there is a change on that page, simply deleting the previously generated file.

When the user visits this page through the browser, the HTML version is served, that is, the script checks if there is any HTML already created, if yes then it is included and the execution ends without any query or processing if not, it does all the processing and saves an HTML to be served later (as a cache).

My question is whether I can do this using compressed HTML, using the ob_start('ob_gzhandler') function instead of just ob_start ();

Is there a compatibility problem, or maybe I have some better method to do what I need?

    
asked by anonymous 07.12.2015 / 03:01

1 answer

1

You can use an alternate form of compaction:

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
    );

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

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

    return $buffer;
}

ob_start("sanitize_output")

Original question:

link

    
07.12.2015 / 13:13