• Stars
    star
    138
  • Rank 258,729 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make flask pages load faster and better by streaming partial HTTP Responses πŸ’₯

FlaskSR contributions welcome

FlaskSR provides an easy way to make flask pages load faster and better by streaming HTTP Responses πŸ’₯

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. 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

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:

from flask import Flask
from flasksr import BasicSR, Dom

app = Flask(__name__)


def render_menu():
    return """
        <ul style="list-style-type: none; margin: 0; padding: 0;">
            <li><a href="/">Home</a></li>
            <li><a href="#">News</a></li>
            <li><a href="#">Contact</a></li>
            <li><a href="#">About</a></li>
        </ul>
    """


def render_body():
    return """
        <div style="margin-top: 50px;">Hello World!</div>
    """

def render_first():
    return """
        <html>
            <head>
                <title>FlaskSR Example</title>
            </head>
            <body>
    """

def render_last():
    return """
            </body>
        </html>
    """


@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 For advanced usage when you want a particular part of your page to get rendered first you can use LayoutSR

Examples

You can find examples and sample usage here

Documentation

Complete documentation for FlaskSR is available on FlaskSR's GitBook.

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!

More Repositories

1

system-design-questions

Problem statements on System Design and Software Architecture as part of Arpit's System Design Masterclass
Python
1,761
star
2

concurrency-in-depth

Go
91
star
3

knowledge-base

88
star
4

database-fundamentals

Prototype implementations of database internal concepts and algorithms in Golang.
Go
72
star
5

obsidian-hackernews

Periodically fetches and displays top stories from HackerNews.
TypeScript
68
star
6

abloom

A pure Go implementation of Bloom Filter.
Go
37
star
7

consistent-hashing

Consistent Hashing implementation in Python
Jupyter Notebook
29
star
8

understanding-virtual-memory

C
27
star
9

fsm

Finite State Machine in Python using Coroutines.
Jupyter Notebook
21
star
10

reweb

Fastest web framework for blog. Built on raw HTML, CSS, and vanilla JS
Python
17
star
11

WikiSe

A wikipedia search engine that is completely built in Java and works on Wikipedia XML dumps
Java
16
star
12

py-prompts

Themes for Python prompts.
Shell
13
star
13

concurrency-with-semaphores

C
13
star
14

tripod

πŸƒ πŸƒ πŸƒSomewhat fast, somewhat optimal Prefix Search in Go
Go
10
star
15

tcpserver

Go
10
star
16

linkie

Extracts meta information about a link πŸ”—
JavaScript
10
star
17

mongo-pagination-benchmark

Benchmarks two approaches to paginate in MongoDB
Python
10
star
18

ls

Implement UNIX Shell command ls using UNIX System calls
C
9
star
19

grpc-in-depth

Go
8
star
20

quora-widget

Un-offical Quora widget and Quora card for your profile
JavaScript
8
star
21

articles

Articles for arpitbhayani.me in markdown format.
C++
8
star
22

recviz

Simple visualization for recursive functions in Python.
Python
6
star
23

grpc-advcalc

Go
6
star
24

genetic-knapsack

Genetic Algorithm for Knapsack Problem
Python
4
star
25

spoj

SPOJ solutions
C++
3
star
26

lfsr

LFSR - Linear Feedback Shift Register
Go
3
star
27

arlt

⚑ Redis backed Rate Limiter [Not For Production]
Go
3
star
28

fractional-cascading

Exhaustive implementation of Fractional Cascading in Python
Jupyter Notebook
3
star
29

badger-cli

Unofficial CLI for Badger DB https://github.com/dgraph-io/badger
Go
3
star
30

endianness

understanding endianness
Go
2
star
31

dqueue

Persistent and fault tolerant queue implementation in Golang.
Go
2
star
32

go-sleep-sort

Sleep Sort Implementation in Go
Go
2
star
33

hackerrank

HackerRank Solutions
C++
2
star
34

arxiv-download

Download research papers from arxiv
Python
2
star
35

go-cgo

Exploring CGO
Go
2
star
36

arpitbbhayani.github.io

My Website ;)
HTML
2
star
37

penny

A martian bot
JavaScript
2
star
38

go-playground

Go
2
star
39

udemy

Udemy to understand low level details and designs.
Python
2
star
40

slowsort

Jupyter Notebook
1
star
41

cpython-patches

Experimental patches on CPython
1
star
42

1d-terrain

Jupyter Notebook
1
star
43

sudoku-solver

Sudoku solver in javascript and p5.js
JavaScript
1
star
44

arpitbbhayani

1
star
45

morris-counter

Jupyter Notebook
1
star
46

editor-demo

Flask application with in built online text editor
JavaScript
1
star
47

DBSystem

Implementation of a DB system. Includes in memory data representation, Query Execution and Optimization
C++
1
star
48

catdb

1
star
49

sepy

In-memory search engine in Python [educational purpose only]
Python
1
star
50

flajolet-martin

Simple python implementation of Flajolet Martin algorithm
Jupyter Notebook
1
star
51

go-pointers-benchmark

Benchmarking pass by value and pass by pointer in Go
Go
1
star
52

ranking-on-ratings

Ranking movies using Arithmetic average, Cumulative Rating and Bayesian Average.
Jupyter Notebook
1
star
53

tfidf

Jupyter Notebook
1
star
54

scrapy_python

scrapy_python
Python
1
star
55

overload

Function overloading for Python
Python
1
star
56

jsoncache

Easy way to manipulate JSON file for Python πŸƒ
Python
1
star
57

scripts-and-snippets

Installing tools, softwares and utilies in one shot
Shell
1
star
58

torrent-leecher

Go
1
star
59

kafka-zero-copy

1
star
60

treeline-expts

Experiments with TreeLine database
CMake
1
star
61

pi-digit-distribution

JavaScript
1
star
62

delta

A sample repository to demonstrate the impact of delta and delta-delta compression.
1
star