Skip to content

Commit

Permalink
Add gzip compression for HTML, JS, and CSS files (#999)
Browse files Browse the repository at this point in the history
## Fixes issue
#996

## Description of Changes
Added gzip compression to HTML, JS, and CSS file responses via the
[`Flask-Compress`
package](https://github.com/colour-science/flask-compress).

Network tab of `http://localhost:3000/department/1` without compression:
<img width="821" alt="Screenshot 2023-07-31 at 12 36 41 PM"
src="https://github.com/lucyparsons/OpenOversight/assets/5885605/1ab41e56-a976-4e3c-83dc-fe3ef0bac16a">

Network tab of `http://localhost:3000/department/1` with compression:
<img width="821" alt="Screenshot 2023-07-31 at 12 32 38 PM"
src="https://github.com/lucyparsons/OpenOversight/assets/5885605/fc09cbec-17b9-4640-9a9d-2348a1b973d3">


## Tests and linting
 - [x] This branch is up-to-date with the `develop` branch.
 - [x] `pytest` passes on my local development environment.
 - [x] `pre-commit` passes on my local development environment.
  • Loading branch information
michplunkett authored Aug 1, 2023
1 parent 9bef4ba commit 66efc24
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions OpenOversight/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from flask import Flask, jsonify, render_template, request
from flask_bootstrap import Bootstrap
from flask_compress import Compress
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask_login import LoginManager
Expand All @@ -20,6 +21,7 @@


bootstrap = Bootstrap()
compress = Compress()

login_manager = LoginManager()
login_manager.session_protection = "strong"
Expand Down Expand Up @@ -52,6 +54,7 @@ def create_app(config_name="default"):
limiter.init_app(app)
login_manager.init_app(app)
sitemap.init_app(app)
compress.init_app(app)

from OpenOversight.app.main import main as main_blueprint

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ email-validator==2.0.0.post2
Faker==18.13.0
Flask==2.3.2
Flask-Bootstrap==3.3.7.1
Flask-Compress==1.13
Flask-Limiter==3.3.1
Flask-Login==0.6.2
Flask-Migrate==4.0.4
Expand Down

0 comments on commit 66efc24

Please sign in to comment.