Bird
0
0

Given this Flask snippet using flask_compress:

medium📝 component behavior Q13 of 15
Flask - Performance Optimization
Given this Flask snippet using flask_compress:
from flask import Flask
from flask_compress import Compress

app = Flask(__name__)
Compress(app)

@app.route('/')
def home():
    return app.send_static_file('style.css')
What happens when a browser requests /?
AThe server sends style.css without compression
BThe server sends an HTML page instead of style.css
CThe server returns a 404 error
DThe server sends the compressed version of style.css
Step-by-Step Solution
Solution:
  1. Step 1: Understand flask_compress effect

    When flask_compress is initialized with the app, it compresses responses automatically if the client supports it.
  2. Step 2: Analyze the route behavior

    The route returns the static file 'style.css' using send_static_file. With compression enabled, this file is sent compressed.
  3. Final Answer:

    The server sends the compressed version of style.css -> Option D
  4. Quick Check:

    flask_compress compresses static files automatically [OK]
Quick Trick: flask_compress compresses all responses including static files [OK]
Common Mistakes:
MISTAKES
  • Assuming static files are never compressed
  • Expecting a 404 error without reason
  • Thinking the route sends HTML by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes