daxlab / Flask-Cache-Buster

A lightweight flask extension that cache-busts static files by adding content-based query parameters to their URLs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask-Cache-Buster is a lightweight Flask extension that adds a hash to the URL query parameters of each static file. This lets you safely declare your static resources as indefinitely cacheable because they automatically get new URLs when their contents change.

Usage

from flask_cache_buster import CacheBuster

config = {
     'extensions': ['.js', '.css', '.csv'],
     'hash_size': 10
}

cache_buster = CacheBuster(config=config)
cache_buster.register_cache_buster(app)

The url_for function will now cache-bust your static files. For example, this template:

<script src="{{ url_for('static', filename='js/main.js') }}"></script>

will render like this:

<script src="/static/js/main.js?%3Fq%3Dc5b5b2fa19"></script>

License

MIT

TODO

  • python 2.7 support
  • add tests

Inspired by ChrisTM/Flask-CacheBust

About

A lightweight flask extension that cache-busts static files by adding content-based query parameters to their URLs

License:MIT License


Languages

Language:Python 100.0%