forked from colour-science/flask-compress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
132 lines (102 loc) · 6.66 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Flask-Compress by libwilliam</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/github-light.css">
<meta name="viewport" content="width=device-width">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<header>
<h1>Flask-Compress</h1>
<p>Compress responses in your Flask app with gzip.</p>
<p class="view"><a href="https://github.com/libwilliam/flask-compress">View the Project on GitHub <small>libwilliam/flask-compress</small></a></p>
<ul>
<li><a href="https://github.com/libwilliam/flask-compress/zipball/master">Download <strong>ZIP File</strong></a></li>
<li><a href="https://github.com/libwilliam/flask-compress/tarball/master">Download <strong>TAR Ball</strong></a></li>
<li><a href="https://github.com/libwilliam/flask-compress">View On <strong>GitHub</strong></a></li>
</ul>
</header>
<section>
<h1>
<a id="flask-compress" class="anchor" href="#flask-compress" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Flask-Compress</h1>
<p><a href="https://pypi.python.org/pypi/Flask-Compress"><img src="https://img.shields.io/pypi/v/flask-compress.svg" alt="Version"></a>
<a href="https://travis-ci.org/libwilliam/flask-compress"><img src="https://travis-ci.org/libwilliam/flask-compress.png" alt="Build Status"></a>
<a href="https://coveralls.io/github/libwilliam/flask-compress"><img src="https://coveralls.io/repos/libwilliam/flask-compress/badge.svg" alt="Coverage"></a>
<a href="https://github.com/libwilliam/flask-compress/blob/master/LICENSE.txt"><img src="https://img.shields.io/pypi/l/flask-compress.svg" alt="License"></a></p>
<p>Flask-Compress allows you to easily compress your <a href="http://flask.pocoo.org/">Flask</a> application's responses with gzip.</p>
<p>The preferred solution is to have a server (like <a href="http://wiki.nginx.org/Main">Nginx</a>) automatically compress the static files for you. If you don't have that option Flask-Compress will solve the problem for you.</p>
<h2>
<a id="how-it-works" class="anchor" href="#how-it-works" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>How it works</h2>
<p>Flask-Compress both adds the various headers required for a compressed response and gzips the response data. This makes serving gzip compressed static files extremely easy.</p>
<p>Internally, every time a request is made the extension will check if it matches one of the compressible MIME types and will automatically attach the appropriate headers.</p>
<h2>
<a id="installation" class="anchor" href="#installation" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Installation</h2>
<p>If you use pip then installation is simply:</p>
<div class="highlight highlight-source-shell"><pre>$ pip install flask-compress</pre></div>
<p>or, if you want the latest github version:</p>
<div class="highlight highlight-source-shell"><pre>$ pip install git+git://github.com/libwilliam/flask-compress.git</pre></div>
<p>You can also install Flask-Compress via Easy Install:</p>
<div class="highlight highlight-source-shell"><pre>$ easy_install flask-compress</pre></div>
<h2>
<a id="using-flask-compress" class="anchor" href="#using-flask-compress" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Using Flask-Compress</h2>
<p>Flask-Compress is incredibly simple to use. In order to start gzip'ing your Flask application's assets, the first thing to do is let Flask-Compress know about your <a href="http://flask.pocoo.org/docs/latest/api/#flask.Flask"><code>flask.Flask</code></a> application object.</p>
<div class="highlight highlight-source-python"><pre><span class="pl-k">from</span> flask <span class="pl-k">import</span> Flask
<span class="pl-k">from</span> flask_compress <span class="pl-k">import</span> Compress
app <span class="pl-k">=</span> Flask(<span class="pl-c1">__name__</span>)
Compress(app)</pre></div>
<p>In many cases, however, one cannot expect a Flask instance to be ready at import time, and a common pattern is to return a Flask instance from within a function only after other configuration details have been taken care of. In these cases, Flask-Compress provides a simple function, <code>flask_compress.Compress.init_app</code>, which takes your application as an argument.</p>
<div class="highlight highlight-source-python"><pre><span class="pl-k">from</span> flask <span class="pl-k">import</span> Flask
<span class="pl-k">from</span> flask_compress <span class="pl-k">import</span> Compress
compress <span class="pl-k">=</span> Compress()
<span class="pl-k">def</span> <span class="pl-en">start_app</span>():
app <span class="pl-k">=</span> Flask(<span class="pl-c1">__name__</span>)
compress.init_app(app)
<span class="pl-k">return</span> app</pre></div>
<p>In terms of automatically compressing your assets using gzip, passing your <a href="http://flask.pocoo.org/docs/latest/api/#flask.Flask"><code>flask.Flask</code></a> object to the <code>flask_compress.Compress</code> object is all that needs to be done.</p>
<h2>
<a id="options" class="anchor" href="#options" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Options</h2>
<p>Within your Flask application's settings you can provide the following settings to control the behavior of Flask-Compress. None of the settings are required.</p>
<table>
<thead>
<tr>
<th>Option</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>COMPRESS_MIMETYPES</code></td>
<td>Set the list of mimetypes to compress here.</td>
<td>
<code>[</code><br><code>'text/html',</code><br><code>'text/css',</code><br><code>'text/xml',</code><br><code>'application/json',</code><br><code>'application/javascript'</code><br><code>]</code>
</td>
</tr>
<tr>
<td><code>COMPRESS_LEVEL</code></td>
<td>Specifies the gzip compression level.</td>
<td><code>6</code></td>
</tr>
<tr>
<td><code>COMPRESS_MIN_SIZE</code></td>
<td>Specifies the minimum file size threshold for compressing files.</td>
<td><code>500</code></td>
</tr>
</tbody>
</table>
</section>
<footer>
<p>This project is maintained by <a href="https://github.com/libwilliam">libwilliam</a></p>
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
</footer>
</div>
<script src="javascripts/scale.fix.js"></script>
</body>
</html>