I'm struggling trying to minify my index.php file
Here is what's in my : index.php
<?php include 'master.php'; ?>
<?php
function htmlmin($buffer)
{
$search = array( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' );
$replace = array('>','<','\\1');
if (preg_match("/\<html/i",$buffer) == 1 && preg_match("/\<\/html\>/i", $buffer) == 1) {
$buffer = preg_replace($search, $replace, $buffer);
}
return $buffer;
}
ob_start("htmlmin");
?>
When I do view page source
, I still see my html output is not minify. I know that I did something wrong, but I'm not sure what it is.
Did I forget to do something ? Am I on the right track ? Can someone please give me hint ?
by using one of the grunt task: grunt-contrib-htmlmin
you may install this plugin with this command:
npm install grunt-contrib-htmlmin --save-dev
Once the plugin has been installed, add this to your Gruntfile
grunt.loadNpmTasks('grunt-contrib-htmlmin');
htmlmin: {
dist: {
files: {
'index.php': 'index.php',
}
}
}
grunt.initConfig({
htmlmin: {
dist: {
files: {
'index.php': 'index.php',
}
}
}
});
// Load NPM Tasks
grunt.loadNpmTasks('grunt-contrib-htmlmin');
// Default Setting
grunt.registerTask('default', ['htmlmin']);
};
Just run grunt
on your terminal, the index.php will be minified.
It will not be fun, If I don't show you guys the result. Here is it.