Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arpitbbhayani/flasksr

Make flask pages load faster and better by streaming partial HTTP Responses :boom:
https://github.com/arpitbbhayani/flasksr

Last synced: 13 days ago
JSON representation

Make flask pages load faster and better by streaming partial HTTP Responses :boom:

Awesome Lists containing this project

README

        

# FlaskSR [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues)

FlaskSR provides an easy way to make flask pages load faster and better by streaming HTTP Responses :boom:

## Why should you use this?

Every web application tries to minimize the "Time to First Paint". This can be done by streaming partial responses to client. FlaskSR enables this functionality in an easy way for [Flask Web Framework](http://flask.pocoo.org/). With FlaskSR you can start streaming partial HTTP responses depending on layout to client so that client starts seeing some content along the way instead of seeing all of the site's content at once and thus making the pages load faster and better.

Advantages:
- Fully compatible with Jinja templates.
- Minimizes Time for first paint.
- No impact on SEO - as nothing goes via AJAX calls.
- Start rendering important part of your page first so user start seeing important things first.
- Improves perceived performance of the page.

## Installation
Install the extension with the following command:

```
$ pip install flasksr
```

## FlaskSR in action
![impact](https://cloud.githubusercontent.com/assets/4745789/19834915/7354d69a-9e9a-11e6-8ab6-b7b95146a25c.gif)

## Usage
Once installed, the FlaskSR is easy to use. Let's walk through setting up a basic application. Also please note that this is a very basic guide: we will be taking shortcuts here that you should never take in a real application.

To begin we'll set up a Flask app:

```py
from flask import Flask
from flasksr import BasicSR, Dom

app = Flask(__name__)

def render_menu():
return """


"""

def render_body():
return """

Hello World!

"""

def render_first():
return """


FlaskSR Example


"""

def render_last():
return """


"""

@app.route('/')
def hello():
return BasicSR(
Dom(render_first),
Dom(render_menu),
Dom(render_body),
Dom(render_last)
).response

if __name__ == '__main__':
app.run(host='0.0.0.0')
```

Above example shows a very basic top down response streaming with [BasicSR](https://arpitbbhayani.gitbooks.io/flasksr/content/sr/basicsr.html) For advanced usage when you want a particular part of your page to get rendered first you can use [LayoutSR](https://arpitbbhayani.gitbooks.io/flasksr/content/sr/layoutsr.html)

## Examples
You can find examples and sample usage [here](https://github.com/arpitbbhayani/flasksr/tree/master/examples)

## Documentation

Complete documentation for FlaskSR is available on [FlaskSR's GitBook](https://arpitbbhayani.gitbooks.io/flasksr/).

## Contributing

We welcome contributions! If you would like to hack on FlaskSR, please follow these steps:

- Fork this repository
- Make your changes
- Submit a pull request after running make check (ensure it does not error!)
- Please give us adequate time to review your submission. Thanks!