I'm trying to minify the css on the fly in WordPress because if I do the minify directly my theme won't work when the comment gets removed.
First I tried to remove comments from any specified css file its working fine here is the code
<?php
$cssfile = 'style.css';//css file needed to minify
$file = fopen($cssfile, 'r');
if ($file) {
$buffer = file_get_contents('style.css');//getting content of css file needed to minify
$buffers = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
echo $buffers;
}?>
Same thing I want to do on the fly. In many tutorialS all uses ob_start()
and saying about http request
. I don't know these things and what they dos and also I am unable to see where they are specifying the file path like I did in the 1st line $cssfile
I think they are telling $_GET[something]
for file. Is this where they mentioning the css file which needs to be minify?(Mentioning path to the css)
Can any one help me on this to do a on the fly css minify with explain of ob_start(), http request and how it works.