Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Created February 21, 2014 21:08
Show Gist options
  • Save bollwyvl/9143557 to your computer and use it in GitHub Desktop.
Save bollwyvl/9143557 to your computer and use it in GitHub Desktop.
A quick and dirty script to use online services to generate minified versions of js and css files next to the originals, such as for CDNJS.
import os
import fnmatch
from urllib import urlopen, urlencode
services = {
"css": "http://cssminifier.com/raw",
"js": "http://javascript-minifier.com/raw"
}
for ext, url in services.items():
files = [os.path.join(dirpath, f)
for dirpath, dirnames, files in os.walk(".")
for f in fnmatch.filter(files, '*.%s' % ext)]
for path in files:
if ".min." + ext in path: continue
out_path = path[:-len(ext):] + "min." + ext
with file(path) as f:
raw = f.read()
post = urlopen(url, urlencode({'input': raw}))
with file(out_path, "w+") as f:
f.write(post.read())
print path, "->", out_path, map(os.path.getsize, [path, out_path])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment