django-htmlmin: Reduzindo tamanho do response com Python

11
django-htmlmin Reduzindo o tamanho do seu response com Python @franciscosouza Friday, July 1, 2011

description

Lighting talk apresentada durante o FISL, na sessão de lighting talks da comunidade Python Brasil.

Transcript of django-htmlmin: Reduzindo tamanho do response com Python

Page 1: django-htmlmin: Reduzindo tamanho do response com Python

django-htmlminReduzindo o tamanho do seu response com Python

@franciscosouzaFriday, July 1, 2011

Page 2: django-htmlmin: Reduzindo tamanho do response com Python

#cobrateam

• Não da tempo :P

Friday, July 1, 2011

Page 3: django-htmlmin: Reduzindo tamanho do response com Python

#cobrateam

• Não da tempo :P

Friday, July 1, 2011

Page 4: django-htmlmin: Reduzindo tamanho do response com Python

#cobrateam

• Não da tempo :P

Já falei!

Friday, July 1, 2011

Page 5: django-htmlmin: Reduzindo tamanho do response com Python

Uma função

from htmlmin.minify import html_minifyprint html_minify(conteudo)

Friday, July 1, 2011

Page 6: django-htmlmin: Reduzindo tamanho do response com Python

E o Django?

Friday, July 1, 2011

Page 7: django-htmlmin: Reduzindo tamanho do response com Python

view decorator

from htmlmin.decorators import minified_response

@minified_responsedef home(request): return render_to_response('home.html')

Friday, July 1, 2011

Page 8: django-htmlmin: Reduzindo tamanho do response com Python

middleware

MIDDLEWARE_CLASSES = ( # other middleware classes 'htmlmin.middleware.HtmlMinifyMiddleware',)

Friday, July 1, 2011

Page 9: django-htmlmin: Reduzindo tamanho do response com Python

Indo além...from functools import wrapsfrom htmlmin.minify import html_minify

def minified_response(function): @wraps(function) def minified_view(*args, **kwargs): return_value = function(*args, **kwargs) if type(return_value) == unicode: return html_minify(return_value.encode('utf-8')) return return_value return minified_view

Friday, July 1, 2011

Page 10: django-htmlmin: Reduzindo tamanho do response com Python

Indo além...

@minified_responsedef home(request): return render_template('home.html')

Friday, July 1, 2011

Page 11: django-htmlmin: Reduzindo tamanho do response com Python

Obrigado!

cobrateam.info

github.com/cobrateam/django-htmlmin

Friday, July 1, 2011