Commit e81a913017ca597fb365f4d594807e6ea8e1d922

Authored by Carlos Vieira
1 parent 306f2ed7
Exists in master

barrabrasil.py: colocando gzip para compressao da barra.

Showing 2 changed files with 9 additions and 4 deletions   Show diff stats
app/barrabrasil.py
1 1 from flask import Flask, url_for, render_template, request, Response, make_response
2 2 from config import Config
3   -import hashlib
  3 +import hashlib, zlib
4 4  
5 5 # Criar Key e certificado
6 6 # openssl genrsa 1024 > ssl.key
... ... @@ -42,14 +42,19 @@ def barra():
42 42 with app.open_resource('templates/%s/barra-brasil.js' % profile) as f:
43 43 conteudo = f.read().decode('utf-8')
44 44 etag = hashlib.sha1(conteudo.encode('utf-8')).hexdigest()
  45 + accept_encoding = request.headers.get('Accept-Encoding', '')
45 46 if request.if_none_match and \
46 47 etag in request.if_none_match:
47 48 resposta = Response(status=304)
  49 + if accept_encoding and \
  50 + 'gzip' in accept_encoding:
  51 + conteudo = zlib.compress(conteudo.encode('utf8'))
  52 + resposta.headers['Content-Encoding'] = 'gzip'
48 53 else: # nao esta em cache do navegador
49 54 resposta = make_response(conteudo)
50 55 resposta.set_etag(etag)
51 56 resposta.headers['Content-type'] = 'application/x-javascript'
52   - resposta.headers['Cache-control'] = 'public, max-age: 86400' #24 horas
  57 + resposta.headers['Cache-control'] = 'public, max-age: 86401' #24 horas
53 58 resposta.headers['Last-Modified'] = data
54 59 return resposta
55 60  
... ... @@ -62,7 +67,7 @@ def fonte():
62 67 conteudo = f.read().decode('base64')
63 68 resposta = make_response(conteudo)
64 69 resposta.headers['Content-type'] = 'application/x-font-woff'
65   - resposta.headers['Cache-control'] = 'public, max-age: 86400' #24 horas
  70 + resposta.headers['Cache-control'] = 'public, max-age: 31536000' #1 ano
66 71 resposta.headers['Last-Modified'] = data
67 72 return resposta
68 73  
... ...
app/profile
1 1 profile : copa2014
2   -date : " Mon, 12 May 2014 15:04:36 -0300 "
  2 +date : " Mon, 12 May 2014 15:52:03 -0300 "
... ...