Compress and minify Flask responses!
Project description
Flask-Squeeze is a Flask extension that automatically:
- Minifies repsonses with the mimetypes javascript and css
- Compresses all HTTP responses with brotli if the browser supports it, or gzip if the browser supports it!
- Caches static files so that they don't have to be re-compressed. The cache will be cleared each time Flask restarts. Files are considered to be static if they contain ".../static/..." in their request path.
Installation
pip3 install Flask-Squeeze
Usage
from flask_squeeze import Squeeze
squeeze = Squeeze()
# Initialize Extension
squeeze.init_app(app)
Thats all!
Options
You can configure Flask-Squeeze with the following options in your Flask config:
COMPRESS_FLAG (default=True)
: Globally enables or disables Flask-SqueezeCOMPRESS_MIN_SIZE (default=500)
: Defines the minimum file size in bytes to activate the compressionCOMPRESS_MINIFY_CSS (default=True)
: Enable or disable css minification using rcssmin.COMPRESS_MINIFY_JS (default=True)
: Enable or disable css minification using rcssmin.COMPRESS_VERBOSE_LOGGING (default=False)
: Enable or disable verbose logging. If enabled, Flask-Squeeze will print what it does into the terminal in a highlighted color.
Compression level options
Static files are chached, so they only have to be compressed once. Dynamic files like generated HTML files will not be cached, so they will be compressed for each response.
COMPRESS_LEVEL_BROTLI_STATIC (default=11, min=0 , max=11)
: Defines the compression level of brotli for static files.COMPRESS_LEVEL_BROTLI_DYNAMIC (default=1, min=0, max=11)
: Defines the compression level of brotli for dynamic files.COMPRESS_LEVEL_GZIP_STATIC (default=9, min=0 , max=9)
: Defines the compression level of gzip for static files.COMPRESS_LEVEL_GZIP_DYNAMIC (default=1, min=0, max=9)
: Defines the compression level of gzip for dynamic files.COMPRESS_LEVEL_DEFLATE_STATIC (default=9, min=-1 , max=9)
: Defines the compression level of gzip for static files.COMPRESS_LEVEL_DEFLATE_DYNAMIC (default=1, min=-1, max=9)
: Defines the compression level of gzip for dynamic files.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_squeeze-2.0.2.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for flask_squeeze-2.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0385d7d49a706e78c275b627361eb2113048b16a0e15bfc71345458bc2f78a0 |
|
MD5 | 56ede4754cd99a11dff2f846944da53c |
|
BLAKE2b-256 | 7cb5b6a96f40bd8aa683d55ea80f57839406ae0d0e1531ec4bbf558cf77fd61d |