PHP code example of websharks / html-compressor
1. Go to this page and download the library: Download websharks/html-compressor library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
websharks / html-compressor example snippets
_compressor = new WebSharks\HtmlCompressor\Core();
ob_start(array($html_compressor, 'compress'));
_compressor = new WebSharks\HtmlCompressor\Core();
ob_start(array($html_compressor, 'compress'));
_compressor_options = array(
'css_exclusions' => array(),
'js_exclusions' => array('.php?'),
'uri_exclusions' => array(),
'cache_expiration_time' => '14 days',
'cache_dir_public' => '/var/www/public_html/htmlc/cache/public',
'cache_dir_url_public' => 'http://example.com/htmlc/cache/public',
'cache_dir_private' => '/var/www/public_html/htmlc/cache/private',
'compress_combine_head_body_css' => TRUE,
'compress_combine_head_js' => TRUE,
'compress_combine_footer_js' => TRUE,
'compress_inline_js_code' => TRUE,
'compress_css_code' => TRUE,
'compress_js_code' => TRUE,
'compress_html_code' => TRUE,
'benchmark' => FALSE,
'product_title' => 'HTML Compressor',
'vendor_css_prefixes' => array('moz','webkit','khtml','ms','o')
);
$html_compressor = new WebSharks\HtmlCompressor\Core($html_compressor_options);
ob_start(array($html_compressor, 'compress'));
_compressor_options = array(
'css_exclusions' => array(),
'js_exclusions' => array('.php?'),
'uri_exclusions' => array(),
'cache_expiration_time' => '14 days',
'cache_dir_public' => '/var/www/public_html/htmlc/cache/public',
'cache_dir_url_public' => 'http://example.com/htmlc/cache/public',
'cache_dir_private' => '/var/www/public_html/htmlc/cache/private',
'current_url_scheme' => 'http',
'current_url_host' => 'www.example.com',
'current_url_uri' => '/raw/file/test.html?one=1&two=2',
'compress_combine_head_body_css' => TRUE,
'compress_combine_head_js' => TRUE,
'compress_combine_footer_js' => TRUE,
'compress_inline_js_code' => TRUE,
'compress_css_code' => TRUE,
'compress_js_code' => TRUE,
'compress_html_code' => TRUE,
'benchmark' => FALSE,
'product_title' => 'HTML Compressor',
'vendor_css_prefixes' => array('moz','webkit','khtml','ms','o')
);
$html = '<html> ... </html>';
$html_compressor = new WebSharks\HtmlCompressor\Core($html_compressor_options);
$html = $html_compressor->compress($html);