2011-08-28, 03:27 PM
This guide is aimed at those of you not afraid to modify core files. I'll be showing you how to make MyBB automatically minimise your CSS files to increase page load speed by a small amount. To do this, we need to modify the file ./admin/inc/functions_themes.php.
Find:
Add after:
What this does is it strips all the comments, spaces and other pieces of whitespace from your stylesheet when it's saved to the cache. It does help a fair bit - especially if you run your site through a page speed analyser such as GTmetrix which all actively look for minimised CSS.
Unfortunately, MyBB's resync_stylesheet() function means that the CSS stored in the database is also minified too. This is a bit of an annoyance and one I'm going to look into (short of removing the whole function or modifying it a lot, there seems little I can do for now). I therefore advise you back up all your styles before performing this code edit.
Also note that you must go into each stylesheet and save it for the changes to take effect.
Find:
$fp = @fopen(MYBB_ROOT."{$theme_directory}/{$filename}", "wb");
if(!$fp)
{
return false;
}
Add after:
$stylesheet = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $stylesheet);
$stylesheet = str_replace(': ', ':', $stylesheet);
$stylesheet = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $stylesheet);
What this does is it strips all the comments, spaces and other pieces of whitespace from your stylesheet when it's saved to the cache. It does help a fair bit - especially if you run your site through a page speed analyser such as GTmetrix which all actively look for minimised CSS.
Unfortunately, MyBB's resync_stylesheet() function means that the CSS stored in the database is also minified too. This is a bit of an annoyance and one I'm going to look into (short of removing the whole function or modifying it a lot, there seems little I can do for now). I therefore advise you back up all your styles before performing this code edit.
Also note that you must go into each stylesheet and save it for the changes to take effect.