searchturbine / phpwee-php-minifier

Open-source (BSD) PHP inline minifier functions for HTML, XHTML, HTML5, CSS 1-3 and Javascript. http://searchturbine.com/php/phpwee
Other
79 stars 46 forks source link

How to minify and merge stylesheets #26

Open lowpez opened 6 years ago

lowpez commented 6 years ago

Hello guys, Thank you for taking the time to pay attention and help me to solve these questions. This is the code i'm using for minify my html:

function sanitize_output($buffer) {
      require_once ("phpwee-php-minifier/phpwee.php");
      return  PHPWee\Minify::html($buffer);
}

1º How can I minimize directly on these tags? . An example code i'll be great.

<link rel="stylesheet" href="css/style1.css">
<link rel="stylesheet" href="css/style2.css">

2º it possible to merge style1.css and style2.css in a single file/call? Greetings!

ashucg commented 6 years ago

@lowpez

  1. Have you tried using output buffers?
  2. I don't think it is possible using PHPWee. I am not sure though, I don't remember doing that actually.
lowpez commented 6 years ago

@ashucg ,

Hello mate, can you share with me an example code of how to use it? I got this for my html

function sanitize_output($buffer) {
     require_once ("phpwee-php-minifier/phpwee.php");
     return  PHPWee\Minify::html($buffer);
}

But how apply this in a specific *.css file?

ashucg commented 6 years ago
  1. I think you are already using output butter as your function looks like callback function for ob_start()
  2. It is a different thing, to combine and minify files. You should take a look at this or use this article
deep42 commented 4 years ago

Hi, I actually could use an example as well.

I tried a simple thing: require_once("res/min/phpwee.php"); $css = file_get_contents("res/css/responsive.css"); var_dump($css); $minified_css = PHPWee\Minify::css($css); var_dump($minified_css);

the last line gives string(0) "" vs. the first dump which outputs the actual CSS.

Everything else (HTML, JS) works.

Thank you.

ashucg commented 4 years ago

Hi @deep42 - I would no longer suggest using this minifier. You should use some of the newer minifiers that are frequently updated and are compatible with latest changes in CSS, JS and PHP worlds. For starters, you can use Minify, I have not used it personally, but it looks good.

deep42 commented 4 years ago

Thanks for the tip, I'll check it out.