Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:57:00+00:00 2026-05-25T15:57:00+00:00

I’m using PHP to create user-agent based dynamic stylesheets with: AddHandler application/x-httpd-php .css And

  • 0

I’m using PHP to create user-agent based dynamic stylesheets with:

AddHandler application/x-httpd-php .css

And I send them to client using gzip (php.ini based):

output_handler = ob_gzhandler

But I also want to minify the content of my dynamic stylesheets in order to get better performances… so, at the end of my stylesheet I put:

input.confirmation
{
<?php if ($Browser == 'lt8') { ?>
    margin-top: 1px;
<?php } else { ?>
    margin-top: 3px;
<?php } ?>
}
<?php echo Minify(ob_get_clean()); ?>

Where “function Minify($CSSCode)” just returns a minified version of the string I put in the argument. The problem is that this just outputs an empty stylesheet. I also tried the following code:

<?php
    $Content = ob_get_contents();
    ob_clean();
    echo Minify($Content);
?>

But I obtain the same result: empty file. If I use instead:

<?php echo Minify(ob_get_contents()); ?>

My shylesheet will contain both unminified and minified code.
A solution I thought about is to concatenate every single stylesheet line inside a variable and print it in the end like this:

$CSSCode  = '';
[...]
$CSSCode .= "#header";
$CSSCode .= "{";
$CSSCode .= "  display: block;";
$CSSCode .= "  height: 100px;";
$CSSCode .= "}";
[...]
echo Minify($CSSCode);

But I would prefer to avoid this practice because:

  1. It will be a real nightmare to modify my CSS after, if needed.
  2. I have only one stylesheet for my whole website and it’s quite long… so transforming it into a variable based stylesheet risks to be really really time expensive.

How can I properly clear and override the output buffer?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:57:00+00:00Added an answer on May 25, 2026 at 3:57 pm

    What you can do is to do an explicit ob_start() again in the beginning of the script so you get a second buffer as they can be nested. In general the compression should take good care of the whitespaces so the gain of the Minify operation should be barely notable in the end.

    As a remark: When generating CSS etc. from a script make sure to set proper cache expiration headers so the client won’t request the CSS files everytime but caches them. This brings a way bigger gain than any of the other things you can do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.