Commit ·
c3be05b
1
Parent(s): 4c89ac0
Perf: 30-day immutable cache for static assets; min-instances 1 for TTFB
Browse files- local_app.py +8 -0
local_app.py
CHANGED
|
@@ -80,6 +80,14 @@ app = Flask(__name__)
|
|
| 80 |
app.secret_key = os.environ.get("FLASK_SECRET", "dev-only-secret-change-me")
|
| 81 |
CORS(app, resources={r"/*": {"origins": "*"}})
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# Share the login session with subdomains (e.g. scan.blind-monkeys.com) so
|
| 84 |
# tools hosted there can recognize logged-in admins. Only widen the cookie
|
| 85 |
# domain when the site is reached via a blind-monkeys.com host; on other
|
|
|
|
| 80 |
app.secret_key = os.environ.get("FLASK_SECRET", "dev-only-secret-change-me")
|
| 81 |
CORS(app, resources={r"/*": {"origins": "*"}})
|
| 82 |
|
| 83 |
+
# Long-cache immutable static assets (all versioned via ?v=N query).
|
| 84 |
+
@app.after_request
|
| 85 |
+
def _cache_static_assets(resp):
|
| 86 |
+
p = request.path or ""
|
| 87 |
+
if p.startswith(("/static", "/css", "/assets")):
|
| 88 |
+
resp.headers["Cache-Control"] = "public, max-age=2592000, immutable"
|
| 89 |
+
return resp
|
| 90 |
+
|
| 91 |
# Share the login session with subdomains (e.g. scan.blind-monkeys.com) so
|
| 92 |
# tools hosted there can recognize logged-in admins. Only widen the cookie
|
| 93 |
# domain when the site is reached via a blind-monkeys.com host; on other
|