From 466e8ccb0ad647fd8e477e881dfddc14c6d7cbc8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 15 Dec 2014 17:28:23 +0200 Subject: Remove output minifier This feature has proven to be problematic and it's not nearly as flexible as a dedicated minifier library like Minify (http://www.minifier.org/, https://github.com/matthiasmullie/minify). The same results in terms of saving traffic can also be achievied via gzip compression (which should also be done on the httpd level, but we also support anyway) and stuff like mod_pagespeed. Reverts PR #965 Related issues as a track record proving how problematic this has been: #2078 #1499 #2163 #2092 #2387 #2637 #2710 #2120 #2171 #2631 #2326 #2795 #2791 #2772 Additionally, the count of contributors suggesting that the only way to fix the minifier problems is to remove it, is around the same as the count of people suggesting the feature to be implemented in the first place. It was experimental anyway ... the experiment failed. --- system/core/Output.php | 208 ------------------------------------------------- 1 file changed, 208 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index e8f0b1590..09d251fe2 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -426,14 +426,6 @@ class CI_Output { // -------------------------------------------------------------------- - // Is minify requested? - if ($CFG->item('minify_output') === TRUE) - { - $output = $this->minify($output, $this->mime_type); - } - - // -------------------------------------------------------------------- - // Do we need to write a cache file? Only if the controller does not have its // own _output() method and we are not dealing with a cache file, which we // can determine by the existence of the $CI object above @@ -784,206 +776,6 @@ class CI_Output { } } - // -------------------------------------------------------------------- - - /** - * Minify - * - * Reduce excessive size of HTML/CSS/JavaScript content. - * - * @param string $output Output to minify - * @param string $type Output content MIME type - * @return string Minified output - */ - public function minify($output, $type = 'text/html') - { - switch ($type) - { - case 'text/html': - - if (($size_before = strlen($output)) === 0) - { - return ''; - } - - // Find all the
,,}msU', $output, $textareas_clean);
-				preg_match_all('{}msU', $output, $javascript_clean);
-
-				// Minify the CSS in all the }msU', $output, $style_clean);
-				foreach ($style_clean[0] as $s)
-				{
-					$output = str_replace($s, $this->_minify_js_css($s, 'css', TRUE), $output);
-				}
-
-				// Minify the javascript in }msU', $output, $javascript_messed);
-					$output = str_replace($javascript_messed[0], $javascript_mini, $output);
-				}
-
-				$size_removed = $size_before - strlen($output);
-				$savings_percent = round(($size_removed / $size_before * 100));
-
-				log_message('debug', 'Minifier shaved '.($size_removed / 1000).'KB ('.$savings_percent.'%) off final HTML output.');
-
-			break;
-
-			case 'text/css':
-
-				return $this->_minify_js_css($output, 'css');
-
-			case 'text/javascript':
-			case 'application/javascript':
-			case 'application/x-javascript':
-
-				return $this->_minify_js_css($output, 'js');
-
-			default: break;
-		}
-
-		return $output;
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Minify JavaScript and CSS code
-	 *
-	 * Strips comments and excessive whitespace characters
-	 *
-	 * @param	string	$output
-	 * @param	string	$type	'js' or 'css'
-	 * @param	bool	$tags	Whether $output contains the 'script' or 'style' tag
-	 * @return	string
-	 */
-	protected function _minify_js_css($output, $type, $tags = FALSE)
-	{
-		if ($tags === TRUE)
-		{
-			$tags = array('close' => strrchr($output, '<'));
-
-			$open_length = strpos($output, '>') + 1;
-			$tags['open'] = substr($output, 0, $open_length);
-
-			$output = substr($output, $open_length, -strlen($tags['close']));
-
-			// Strip spaces from the tags
-			$tags = preg_replace('#\s{2,}#', ' ', $tags);
-		}
-
-		$output = trim($output);
-
-		if ($type === 'js')
-		{
-			// Catch all string literals and comment blocks
-			if (preg_match_all('#((?:((??@\[\]^`{|}~])\s*#'	=> '$1',	// Remove spaces following and preceeding JS-wise non-special & non-word characters
-				'#\s{2,}#'					=> ' '		// Reduce the remaining multiple whitespace characters to a single space
-			);
-		}
-		else
-		{
-			$patterns = array(
-				'#/\*.*(?=\*/)\*/#s'	=> '',		// Remove /* block comments */
-				'#\n?//[^\n]*#'		=> '',		// Remove // line comments
-				'#\s*([^\w.\#%])\s*#U'	=> '$1',	// Remove spaces following and preceeding non-word characters, excluding dots, hashes and the percent sign
-				'#\s{2,}#'		=> ' '		// Reduce the remaining multiple space characters to a single space
-			);
-		}
-
-		$$varname = preg_replace(array_keys($patterns), array_values($patterns), $$varname);
-
-		// Glue back JS quoted strings
-		if ($type === 'js')
-		{
-			$js_code += $js_literals;
-			ksort($js_code);
-			$output = implode($js_code);
-			unset($js_code, $js_literals, $varname, $patterns);
-		}
-
-		return is_array($tags)
-			? $tags['open'].$output.$tags['close']
-			: $output;
-	}
-
 }
 
 /* End of file Output.php */
-- 
cgit v1.2.3-24-g4f1b