PrestaShop: Minifying HTML source code

PrestaShop 1.4 introduced a feature called “Minify HTML” to improve performance. In this how to you will find how to add this exciting feature to PrestaShop 1.3!

  1. Download PrestaShop (the latest version of 1.5 branch).
  2. Extract prestashop/tools/minify_html/minify_html.class.php file from the package.
  3. Copy minify_html.class.php file to tools/minify_html/ directory (you will have to create this directory).
  4. Create a new file Media.php with the following content and put it to the class directory:
    * 2007-2013 PrestaShop 
    * This source file is subject to the Open Software License (OSL 3.0)
    * that is bundled with this package in the file LICENSE.txt.
    * It is also available through the world-wide-web at this URL:
    * If you did not receive a copy of the license and are unable to
    * obtain it through the world-wide-web, please send an email
    * to so we can send you a copy immediately.
    * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
    * versions in the future. If you wish to customize PrestaShop for your
    * needs please refer to for more information.
    *  @author PrestaShop SA <>
    *  @copyright  2007-2013 PrestaShop SA
    *  @license  Open Software License (OSL 3.0)
    *  International Registered Trademark & Property of PrestaShop SA
    class	Media extends ObjectModel
    	public static function minifyHTML($html_content)
    		if (strlen($html_content) > 0)
    			//set an alphabetical order for args
    			/*$html_content = preg_replace_callback(
    				array('Media', 'minifyHTMLpregCallback'),
    			$html_content = str_replace(chr(194).chr(160), '&nbsp;', $html_content);
    			if (trim($minified_content = Minify_HTML::minify($html_content, array('xhtml' => true))) !=  '')
    				$html_content = $minified_content;
    			return $html_content;
    		return false;
    	public static function minifyHTMLpregCallback($preg_matches)
    		$args = array();
    		preg_match_all('/[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']/is', $preg_matches[2], $args);
    		$args = $args[0];
    		// if there is no args in the balise, we don't write a space (avoid previous : <title >, now : <title>)
    		if (empty($args))
    			$output = $preg_matches[1].'>';
    			$output = $preg_matches[1].' '.implode(' ', $args).'>';
    		return $output;
    	public static function getBackTrackLimit()
    		static $limit = null;
    		if ($limit === null)
    			$limit = @ini_get('pcre.backtrack_limit');
    			if (!$limit)
    				$limit = -1;
    		return $limit;
  5. Open config/ file.


    $smarty->debug_tpl		= _PS_ALL_THEMES_DIR_ . 'debug.tpl';

    After, add:

    function smartyMinifyHTML($tpl_output, &$smarty)
        $tpl_output = Media::minifyHTML($tpl_output);
        return $tpl_output;


    $smarty->compile_check	= false;

    Before, add:


Save and close all files and it’s done!

Leave a Reply

Your email address will not be published. Required fields are marked *


Cart Check out  »

Prices are tax inclusive.

The VAT rate for your country (US) * is 0,0 % because it is not a member of the European Union (EU).

* Please create an account if your country does not match.

Community feed
  • [phpBB] How to disable Magic SEO URLs 5.0?
    Hello ! permanently disable Magic SEO URL for phpBB v3.0 / 3.1 5.0 is it possible ?
    by Binano
  • [PrestaShop Theme Provider] PHP 7
    Hello, I couldn't find any answer about my question so I write it down. I have a problem with the installation of prestashop theme provider. It says that the PrestaShop Theme Provider Free core...
    by vicochips
  • [BB2PS] Missing header
    Hi, we are using this product: ... stashop-41 but we have a warning and the prestashop header not appear. The prestashop page is:...
    by juanag
  • [WP Accelerator] How do I troubleshoot layout problems?
    Hi I am running the latest version of WordPress Accelerator (v1.2.06) and when I turn this on, the top navigation bar layout does not render properly: If I...
    by markwoodroof
  • [Zen Cart] Change the default HTTP 404 page
    Hi there I cannot find how to change the page an incorrect category url gets defaulted to. I have Magic SEO installed and if I type in an incorrect category id to the url it sends me to the...
    by sthomasmccarthy
Join our support forum » Pre-Sales Questions »
Featured Testimonials

Just wanted to let you know that I got it working :-) It's an awesome product you've got there!

Justin, the owner of Fokvereniging VWF

I was a little concerned about using a 3rd party SEO module for osCommerce - there were some well established ones and they were free - Magic SEO URLs for osCommerce were paid for! But I was looking at my sites and getting concerned with duplicate content - everything was being duplicated and the search engines (allegedly) look down on...

Martin, the owner of Milton Gems and Shop4Silver

More Testimonials »