Giter Site home page Giter Site logo

flask-optimize's Introduction

Flask-optimize

Build Status

Flask optimization using cache, minify html and compress response

https://pypi.python.org/pypi/flask-optimize

Optimize parameters

init_app:

config: Global config

Default:

{
    'html': {'htmlmin': True,  'compress': True, 'cache': 'GET-84600'},
    'json': {'htmlmin': False, 'compress': True, 'cache': False},
    'text': {'htmlmin': False, 'compress': True, 'cache': 'GET-600'}
}

html, json, text: keys for data type of response, see detail below

config_update: update into default global config

optimize

dtype: Data type of response, will get value corresponding with key in global config.

  • html (default)
  • text
  • json

htmlmin: Override htmlmin in config by key dtype

None: using default value from global config
False: disable
True: enable minify html

compress: Override compress in config by key dtype

None: using default value from global config
False: disable
True: enable compress content (using gzip)

cache: Override cache in config by key dtype

None: using default value from global config
False: disable
integer value: enable all method, value is cached period (seconds)
GET-84600: enable for GET method only, cached period is 84600 seconds

Python code usage

from flask import Flask
from flask_optimize import FlaskOptimize

flask_app = Flask(__name__)
flask_optimize = FlaskOptimize()

@flask_app.route('/')
@flask_optimize.optimize()
def index():
    return 'using Flask-optimize'

@flask_app.route('/html')
@flask_optimize.optimize()
def html():
    return '''
    <html>
    <body>
    Default data type is html.
    This content will be minified.
    </body>
    </html>
    '''
    
@flask_app.route('/text')
@flask_optimize.optimize('text')
def text():
    return '''
    <html>
    <body>
    Data type response is text, so this content wasn't minified
    </body>
    </html>
    '''
    
@flask_app.route('/json')
@flask_optimize.optimize('json')
def json():
    return {'text': 'anything', 'other_values': [1, 2, 3, 4]}

if __name__ == '__main__':
    flask_app.run('localhost', 8080, debug=True)

Install

pip install flask-optimize

Requirements:

  • Python 2.x
  • Python 3.x

flask-optimize's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flask-optimize's Issues

Conflicts with frozen-flask

Something strange happens when I try using this with Frozen Flask; seems like something's crashing, then getting binary content ... ?

I get properly minified HTML from regular live flask; I get proper output from non-optimized frozen-flask. And I get garbage binary stuff from optimized frozen.

ImportError: cannot import name FlaskOptimize

Hi, I installed flask-optimize from the Github repository with $ sudo python setup.py install and it got installed successfully. After that I imported it just like in the example in the README file, like

from flask_optimize import FlaskOptimize

But I keep getting ImportError: cannot import name FlaskOptimize
Do you know what the problem could be? I am running Python 2.7 on Ubuntu 16.04.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.