Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

About minifying inside template_css()

Started by asmith, February 01, 2016, 03:39:35 AM

Previous topic - Next topic



I couldn't find a topic for that.
There's an integration function at the start of template_css() with the comment "Use this hook to minify/optimize CSS files".

Could you please tell me how such thing would work?

This is off the top of my head:
We have the $context['css_files'] available there. So I could get each css file and md5_file() it and check on a folder on the server to see if a cache like that exists:

foreach ($context['css_files'] as $id => $file_info)
//  $id isn't the file path here. Not sure if it is available at this point, but you get the concept ...
$minified_target_file md5_file($id) . '.css';
      if (!

$context['css_files'][$id]['filename'] = $minified_target_file;

Original file must disabled. Otherwise it could be access directly.

Am I on the right track here?