This isn’t really specific to WordPress, but it preserves the first comment for WordPress theme management, WordPress is awesome, and I’m specifically using this for WordPress style sheets, so I’m making the connection.

I wrote this script to condense my style sheets into smaller files for faster download times. I’m all about customer service here.

And it’s pleasing to me to distill the CSS into a purer essence and reduce network overhead. (Not that the throngs of visitors to this site are noticeably plugging the tubes.)

One benefit of using compression this way is that I can be more liberal in my stylesheet comments, knowing they won’t burden the “production” .css file delivered to my patrons.

I didn’t go for maximum shrinkage, but this provides sufficient minification for my tastes. Read below for additional commentary and caveats.

(I’m putting this in the public domain. Use at your own risk!)

css_shrinker.py

#!/usr/bin/python3

import sys
import re

css = open(sys.argv[1], 'r').read()
unshrunk_size = len(css)

# save first comment which wordpress needs to display …