开发者

Combining CSS files into a single cached one

开发者 https://www.devze.com 2023-03-14 22:57 出处:网络
I\'m creating a theme where i want it to have different widgets and plugins. Each plugin would ideally have it\'s own css file. However, this approach is not so good because i can end up having multip

I'm creating a theme where i want it to have different widgets and plugins. Each plugin would ideally have it's own css file. However, this approach is not so good because i can end up having multiple f开发者_如何学编程iles included in my header.

Is there an approach where i can sort of cache all different css files in a single one upon the first user request and then just use that ?


Just use only one css with all the different styles from each plugin in that single file. This way you'll end up having only one external css file and it will be cached, saving bandwitdh and decreasing loading times of the page.


Maybe look at things like yui compressor http://developer.yahoo.com/yui/compressor/


In case anyone is still interested, I created a PHP class that combines all the files .css or .js files of the specified folder into one and minimize it. It can be found in my public github. For using it, just do:

if (file_exists('minimize.php')) =
  {
  include 'minimize.php';
  $Minimize = new Minimize();
  $Minimize->folder('/path/to/the/folder/','.css','/path/to/the/resulting/file/style.css');
  }
else
  echo "The minimizer file was not found, please make sure it's in this folder";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号