Bird
0
0

You want to serve static files efficiently with WhiteNoise and also enable long-term caching. Which combination of settings is best?

hard📝 state output Q15 of 15
Django - Deployment and Production
You want to serve static files efficiently with WhiteNoise and also enable long-term caching. Which combination of settings is best?
AAdd WhiteNoise middleware after SecurityMiddleware and set STATICFILES_STORAGE to 'whitenoise.storage.CompressedManifestStaticFilesStorage'
BAdd WhiteNoise middleware at the start of MIDDLEWARE and set STATICFILES_STORAGE to 'django.contrib.staticfiles.storage.StaticFilesStorage'
CDo not add WhiteNoise middleware and set STATICFILES_STORAGE to 'whitenoise.storage.CompressedStaticFilesStorage'
DAdd WhiteNoise middleware after SessionMiddleware and set STATICFILES_STORAGE to 'django.contrib.staticfiles.storage.StaticFilesStorage'
Step-by-Step Solution
Solution:
  1. Step 1: Middleware placement for WhiteNoise

    WhiteNoise middleware must be placed immediately after SecurityMiddleware for proper static file serving.
  2. Step 2: Choosing STATICFILES_STORAGE for caching

    'CompressedManifestStaticFilesStorage' compresses files and adds hashes for long-term caching, which is best practice.
  3. Step 3: Evaluate other options

    Other options either place middleware incorrectly or use storage classes that don't support long-term caching well.
  4. Final Answer:

    Add WhiteNoise middleware after SecurityMiddleware and set STATICFILES_STORAGE to 'whitenoise.storage.CompressedManifestStaticFilesStorage' -> Option A
  5. Quick Check:

    Correct middleware order + caching storage = B [OK]
Quick Trick: Middleware after SecurityMiddleware + CompressedManifestStaticFilesStorage for caching [OK]
Common Mistakes:
MISTAKES
  • Placing middleware too early or late
  • Using default storage without hashing
  • Skipping middleware but setting storage
  • Using storage without compression or hashing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes