Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/italomaia/flask-rev

Allows you to keep an aggressive cache policy with your HTTP server while using flask.
https://github.com/italomaia/flask-rev

files flask hash python static

Last synced: 28 days ago
JSON representation

Allows you to keep an aggressive cache policy with your HTTP server while using flask.

Awesome Lists containing this project

README

        

![travis status](https://travis-ci.org/italomaia/flask-rev.svg?branch=master)

# Flask-Rev

Flask-Rev is a very simple flask extension that aims to make it easier to integrate
flask and those fancy reactive javascript front-ends out there (react, angular, vuejs...).
It allows you to keep an aggressive cache with your HTTP server **AND** always return fresh
static content to user requests. It does so by appending the static file hash to the static
file's url as a query string parameter.

Notice that appending the hash only happens when debug mode is False. Also, be aware
that the hash cache is created during runtime. So, you may experience some
"warming up" slow-down in the first request. This behavior might change in the
future.

**The advantage of this approach**? Your static files
names won't change between updates.

This plugin is heavely based upon these two snippets:

* https://gist.github.com/mfenniak/2978805
* https://gist.github.com/Ostrovski/f16779933ceee3a9d181#file-flask_static_files_cache_invalidator-py-L20

Thanks!

## Installation

pip install flask-rev

## Usage
```py
from flask import Flask, url_for
from flask_rev import Rev

app = Flask(__name__)
Rev(app)

url_for('static', filename='bundle.js')
# outputs: /static/bundle.js?h=
```

## Running Tests

```bash
> python3 setup.py test
> # or
> tox
```