quick search:
 

Optimize XHTML, HTML or CSS

Submitted by: peterbe
Last Edited: 2004-10-14

Category: Python(External Method)

Average rating is: 0.0 out of 5 (0 ratings)

Description:
Suppose you have a chunk of XHTML, HTML or CSS that you want to
optimize, then you can use the slimmer module from
CheckoutableTemplates (http://zope.org/Members/peterbe/CheckoutableTemplates).
It attempts to strip out anything that is
not content so you can save some bytes for the end user.


Source (Text):
from Products.CheckoutableTemplates import slimmer

def MyHTMLSlimmer(html):
    return slimmer.html_slimmer(html)

def MyXHTMLSlimmer(xhtml):
    return slimmer.xhtml_slimmer(html)

def MyCSSSlimmer(css):
    return slimmer.css_slimmer(css)

def AnySlimmer(code, syntax='html'):
    syntax = slimmer.acceptableSyntax(syntax)
    if not syntax:
        m = "%s not in %s"%(syntax, slimmer.OK_SYNTAX)
        raise "InvalidSyntax", m
    if syntax == 'css':
        return slimmer.css_slimmer(code)
    elif syntax == 'xhtml':
        return slimmer.xhtml_slimmer(code)
    else:
        return slimmer.html_slimmer(code)

Explanation:
Save the code about into a 'Extensions/MySlimmer.py' and then you can
create External Methods in Zope with the above mentioned function names.

See http://www.peterbe.com/plog/blogitem-040406-1/compressor
for an example application of this.


Comments:

No Comments