Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove comments from css #640

Open
ProgrammerNomad opened this issue Sep 26, 2018 · 2 comments
Open

How to remove comments from css #640

ProgrammerNomad opened this issue Sep 26, 2018 · 2 comments

Comments

@ProgrammerNomad
Copy link

Hello

All is working fine,

only i am want to remove/hide all css comments from minify output so please help me.

Thanks

@AgentSmith0
Copy link

I would also like to know how to do this.

@sedimentation-fault
Copy link

So you want to only strip comments off your CSS...read on!

How to strip comments only from CSS with minify

This is not something that is supported out-of-the-box, but if you are willing to do some really tiny hacking, you will get it working! This is what you must do:

I suppose you have the source code somewhere, let's say it is in a directory called minify. Open minify/lib/Minify/CSS/Compressor.php and replace the whole function

protected function _process($css)
{
...
}

with this one

protected function _process($css)
{
	// apply callback to all valid comments (and strip out surrounding ws)
	$pattern = '@\\s*/\\*([\\s\\S]*?)\\*/\\s*@';
	$css = preg_replace_callback($pattern, array(get_called_class(), '_commentCB'), $css);

	return trim($css);
}

That's it! Have fun stripping comments only off your CSS. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants