Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#18321 closed enhancement (wontfix)

Stop minimizing CSS files and add a simple regexp in load-scripts.php to remove comments when concatenating

Reported by: azaozz's profile azaozz Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description

As the title, differences in gzipped .dev.css and .css files are minimal. If we remove comments on the fly in load-scripts.php (has to be very fast regexp) we wouldn't need to pre-minimize css files.

Change History (3)

#1 @scribu
13 years ago

It would certainly make changesets easier to review.

#2 @GaryJ
13 years ago

  • Cc gary@… added

Here's a rework of a function I'm using for simplified minifying. For use as a potential starting point for someone (I'm sure it could be optimised):

/**
 * Quick and dirty way to mostly minify CSS.
 *
 * @param string $css String of CSS to minify.
 * @return string
 */
function wp_minify_css( $css ) {

	// Normalize whitespace
	$css = preg_replace( '/\s+/', ' ', $css );

	// Remove comment blocks, everything between /* and */, unless
	// preserved with /*! ... */
	$css = preg_replace( '/\/\*[^\!](.*?)\*\//', '', $css );

	// Remove space after , : ; { }
	$css = preg_replace( '/(,|:|;|\{|}) /', '$1', $css );

	// Remove space before , ; { }
	$css = preg_replace( '/ (,|;|\{|})/', '$1', $css );

	// Strips leading 0 on decimal values (converts 0.5px into .5px)
	$css = preg_replace( '/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $css );

	// Strips units if value is 0 (converts 0px to 0)
	$css = preg_replace( '/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $css );

	// Converts all zeros value into short-hand
	$css = preg_replace( '/0 0 0 0/', '0', $css );

	return apply_filters( 'wp_minify_css', $css );

}

It would be good if something like this was kept as a function re-usable by themes / plugins, rather than them having to include a heavy-weight 3rd-party library to minify strings of CSS.

#3 @nacin
10 years ago

  • Component changed from General to Build Tools
  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

The build process (and before that, bumpbot) has safely rendered this moot.

Note: See TracTickets for help on using tickets.