Crosstips.org

My fun Crossword solver project. Crosstips.org & Krysstips.se

Kung Fu

Fujian White Crane Kung Fu

Fry-IT

Fry-IT is the company I work for

Photos

Photoalbum, both old and new.

Zope

What I have and am doing with Zope

Receptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact me

My contact details and how to contact me.

 

KungFuPeople.com
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com


Mobile version of this page Mobile version of this page


 

slim, a new free web service for white space optimisation


25th of July 2006

If you have some code that you need to optimise, like some Javascript code that is well commented but costs too many bytes of download for your users then you might want to use my slimmer web service. I'll let a Python example speak for itself:

 >>> import xmlrpclib
 >>> s=xmlrpclib.Server('http://www.peterbe.com/')
 >>> css='h1 { font-family: Arial, Verdana; }'
 >>> s.slim(css)
 'h1{font-family:Arial,Verdana}'

Basically, on www.peterbe.com there's a XML-RPC web service called slim which takes two parameters: code and syntax. The second parameter accepts either css, js, html or xhtml and if you don't bother passing anything (like in the example above), the program will do a qualified guess. Here are some more examples:

 >>> js='''function (variable1, variable2) {
 ...   if (variable1 == variable2) {
 ...     return true;
 ...   } else { 
 ...     return false; 
 ...   }
 ... }'''

 >>> s.slim(js, 'js')
 'function (_0,_1) {if(_0==_1){return true;}else{return false;}}'
 >>> html='''<a href="a"  title=" test ">
 ...  <strong> TEST </strong> </a>
 ... <!-- some comment -->
 ... '''

 >>> s.slim(html, 'html')
 '<a href="a" title=" test "><strong> TEST </strong></a>'

If you think XML-RPC is too fancy, you can use HTTP POST instead. To test it create a form in HTML like this:

 <form action="http://www.peterbe.com/slim" method="post">
 <textarea name="code"></textarea>
 <input name="syntax" value="html">
 <input type="submit">
 </form>

And when you submit that form it'll return the code provided with all excess whitespace removed. Example here



Comment

cemilxx - 4th June 2008  [«« Reply to this]
about css parameters
http://css-lessons.ucoz.com/css-parameters.htm
 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.