Call (877) SITE-OPT (748-3678)

Code: Remove CSS comments

From Chapter 7: CSS Optimization

Another strategy is to use PHP comments in your CSS. Once parsed, these comments will automatically disappear. First, you need to tell your server to parse your CSS files for PHP by adding the following lines to your httpd.conf or .htaccess file:

AddHandler application/x-httpd-php .css
php_value default_mimetype "text/css"

Next, include one- or multiline comments within your CSS file:

<?php
// this comment will disappear, a one-liner
?>

For multiline comments:

<?php
/* multiline comment here, allows longer
comments, that also don't appear in your CSS
*/
?>

Again, you trade some server processing power for size.

Copyright © 2002-2017 Website Optimization, LLC. All Rights Reserved - Free website speed test - Privacy Policy
Last modified: February 19, 2009.

Follow us on: Twitter, Google+, Facebook, Linked In