minify icon indicating copy to clipboard operation
minify copied to clipboard

Remove Multiline Comments using callback (postProcess)

Open Concept211 opened this issue 8 years ago • 1 comments

Has anyone figured out a successful way of removing the remaining comments and multiline comments that remain after minification?

I know this is by design to keep the copyrights intact, but tools like GTmetrix consider the files not fully compressed and always suggest further reduction of file size by removing the comments and line breaks.

I've tried cleaning up the code via the postProcess() callback function, but all of the Regex masks that I try to use end up breaking my scripts.

Any help or direction would be greatly appreciated!

Concept211 avatar Mar 24 '17 19:03 Concept211

Nevermind. Ended up writing my own expression instead of using suggested ones and it works great. Here's the snippet if anyone needs it:

// Remove Comments
function postProcess($content, $type) {
	$content = preg_replace('~\/\*\!.*?\*\/~s', "\n", $content);
	$content = trim($content);
	return $content;
}
$min_serveOptions['postprocessor'] = 'postProcess';

Concept211 avatar Mar 24 '17 20:03 Concept211

Hello. In which file and where to insert this code? I pasted into config.php but it doesn't work.

gozna avatar Feb 21 '21 10:02 gozna