Flask-Minify
raw JSON → 0.50 verified Fri May 01 auth: no python
Flask extension that automatically minifies HTML, CSS, JS and Less responses using various minifiers. Current version 0.50, released April 2025. Active development, roughly quarterly releases.
pip install flask-minify Common errors
error AttributeError: module 'flask_minify' has no attribute 'Minify' ↓
cause Old version (pre-0.39) used a different import pattern; or a stale cached .pyc.
fix
Upgrade to latest: pip install --upgrade flask-minify. Also clear __pycache__ if needed.
error ImportError: cannot import name 'minify_response' from 'flask_minify' ↓
cause The decorator was moved to the main module in 0.50. Old imports from flask_minify.decorators break.
fix
Use 'from flask_minify import minify_response' for version >=0.50.
error TypeError: Minify() got an unexpected keyword argument 'dash' ↓
cause The 'dash' parameter was removed in version 0.49.
fix
Remove the 'dash' argument from Minify() call. It is no longer supported.
error pip install flask-minify fails with error: legacy-install-failure (or similar) ↓
cause Missing build dependencies or incompatible Python version (e.g., Python 3.7 before 0.49).
fix
Upgrade Python to >=3.8; install wheel: pip install wheel; then retry.
Warnings
breaking In version 0.49, support for Python 3.7 was dropped and the dash option (--dash) was removed. Upgrade Python to 3.8+. ↓
fix Use Python >=3.8; remove any usage of the 'dash' parameter.
deprecated The `htmlmin` backend is unmaintained; the library switched to a fork in 0.43. Using htmlmin may cause compatibility issues in the future. ↓
fix Use the default backend or install tdewolff-minify (pip install flask-minify[tdewolff]) for better support.
gotcha If you install only the base package, minification of CSS/JS may silently fail because cssmin/jsmin are optional dependencies. The extension will still serve the original content without error. ↓
fix Install with extras: pip install flask-minify[htmlmin] or pip install flask-minify[tdewolff] to ensure minifiers are available.
gotcha The `minify_response` decorator does not work on class-based views (MethodView). It only works on view functions. ↓
fix Use the global Minify(app=app) initialization for class-based views, or apply the decorator manually inside the method's return.
gotcha Less compilation is only triggered if the response has a .less extension. If you serve Less files with a wrong Content-Type, it won't compile. ↓
fix Ensure your route returns files with .less extension, or override the Content-Type header to text/less.
Install
pip install flask-minify[htmlmin] pip install flask-minify[tdewolff] Imports
- Minify
from flask_minify import Minify - decorators wrong
from flask_minify.decorators import minify_responsecorrectfrom flask_minify import minify_response
Quickstart
from flask import Flask
from flask_minify import Minify
app = Flask(__name__)
Minify(app=app, html=True, css=True, js=True)
@app.route('/')
def index():
return '<html><body><h1>Hello</h1></body></html>'
if __name__ == '__main__':
app.run()