slim, a new free web service for white space optimisation

25 July 2006   1 comment   Python

Mind That Age!

This blog post is 11 years old! Most likely, its content is outdated. Especially if it's technical.

Powered by Fusion×

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('https://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="https://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

Comments

cemilxx
Thank you for posting a comment

Your email will never ever be published


Related posts

Previous:
Spaceinvaders with real people 22 July 2006
Next:
slim in ruby 26 July 2006
Related by Keyword:
A Django base class for all your Forms 16 November 2013
HTML whitespace "compression" - don't bother! 11 March 2013
The awesomest way possible to serve your static stuff in Django with Nginx 24 March 2010
Comparing YUI Compressor and slimmer 17 November 2009
Automatically strip whitespace in Django forms 12 October 2009
Related by Text:
slim in ruby 26 July 2006
How to use premailer as a command line script 13 July 2012
AJAX accelerated web widgets 23 June 2005
Premailer.io 08 July 2015
CSS selector bug in IE? 05 December 2006