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

Your email will never ever be published.

Previous:
Spaceinvaders with real people July 22, 2006 Misc. links
Next:
slim in ruby July 26, 2006 Linux
Related by category:
How I run standalone Python in 2025 January 14, 2025 Python
get in JavaScript is the same as property in Python February 13, 2025 Python
How to resolve a git conflict in poetry.lock February 7, 2020 Python
Best practice with retries with requests April 19, 2017 Python
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
HTML whitespace "compression" - don't bother! March 11, 2013 Web development
Automatically strip whitespace in Django forms October 12, 2009 Django