URL: https://www.peterbe.com/stylesheet.css

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

Comments

Your email will never ever be published.

Previous:
World Press Photo, the winners March 4, 2004 Photos
Next:
Moving Image Contest for Creative Commons March 5, 2004 Misc. links
Related by category:
Aggressively prefetching everything you might click August 20, 2014 This site
Photos from FWC China 2005 January 27, 2006 This site
Wattvision - real-time energy monitoring April 27, 2014 This site
Dream: python bindings for squidclient October 11, 2005 This site
Related by keyword:
Fastest way to uniqify a list in Python August 14, 2006 Python
How do you thousands-comma AND whitespace format a f-string in Python March 17, 2024 Python
Premailer.io July 8, 2015 Python, Web development, AngularJS, JavaScript
mincss "Clears the junk out of your CSS" January 21, 2013 Python, Web development