
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com
Mobile version of this page
Previous:
World Press Photo, the winners
Next:
Moving Image Contest for Creative Commons
Practical CSS
10 reasons for web standards
Gzip and Slimmer optimization anecdote
slim, a new free web service for white space optimisation
premailer.py - Transform CSS into line style attributes with lxml.html
Good design examples for a non-blog
More optimization of Peterbe.com - CSS sprites
Fastest way to uniqify a list in Python
Date formatting in Python or in PostgreSQL (part II)
Quick PostgreSQL optimization story
Python optimization anecdote
The problem with CSS
The awesomest way possible to serve your static stuff in Django with Nginx
Optimize Plone.org with slimmer.py
Automatically strip whitespace in Django forms
World Press Photo, the winners
Next:
Moving Image Contest for Creative Commons
Related blogs
XHTML, HTML and CSS compressorPractical CSS
10 reasons for web standards
Gzip and Slimmer optimization anecdote
slim, a new free web service for white space optimisation
premailer.py - Transform CSS into line style attributes with lxml.html
Good design examples for a non-blog
More optimization of Peterbe.com - CSS sprites
Fastest way to uniqify a list in Python
Date formatting in Python or in PostgreSQL (part II)
Quick PostgreSQL optimization story
Python optimization anecdote
The problem with CSS
The awesomest way possible to serve your static stuff in Django with Nginx
Optimize Plone.org with slimmer.py
Automatically strip whitespace in Django forms
Related by category
Optimized stylesheets
http://www.peterbe.com/stylesheet.css4th of March 2004
I have been experimenting recently with HTML optimization but haven't applied it yet. But I have applied this now to my stylsheets. The size gain is 33%! (1577 bytes to 1027 bytes) However, the speed gain involves also the time to perform the optimization so the speed gain will obviously be less than 33%. But the optimization takes, on this slow computer, 0.004 seconds so in approximate terms the speed gain is also 33%. This is on a stylesheet file with some but short and few comments.
The optimization script removes almost all unnecessary whitespace (newline characters included) and all comments. The code for python friends looks like this:
import re
css_comments = re.compile(r'/\*.*?\*/', re.MULTILINE|re.DOTALL)
def _css_slimmer(css):
css = css_comments.sub('', css)
css = re.sub(r'\s\s+', '', css)
css = re.sub(r'\s+{','{', css)
css = re.sub(r'\s}','}', css)
css = re.sub(r'}','}\n', css)
return css
css_comments = re.compile(r'/\*.*?\*/', re.MULTILINE|re.DOTALL)
def _css_slimmer(css):
css = css_comments.sub('', css)
css = re.sub(r'\s\s+', '', css)
css = re.sub(r'\s+{','{', css)
css = re.sub(r'\s}','}', css)
css = re.sub(r'}','}\n', css)
return css
Tweet


Save this page in del.icio.us
See http://www.peterbe.com/XHTML,HTML,CSS-compressor instead now.