Problem/Motivation
Testing Drupal 9 Websites with Google Pagespeed or GTMetrix
If your static files do not change (or you have an appropriate strategy for cache busting), then we recommend setting your cache policy to 6 months or 1 year.
For completed websites, things like global CSS/JS files, logos, images, etc., generally do not change much, and so 6 months or 1 year is a good cache expiry to work with.
(https://gtmetrix.com/serve-static-assets-with-an-efficient-cache-policy....)
We recommend a minimum cache time of one week and preferably up to one year for static assets, or assets that change infrequently. If you need precise control over when resources are invalidated, we recommend using a URL fingerprinting or versioning technique - see invalidating and updating cached responses link above.
https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
Steps to reproduce
Test a Drupal 9 website using Apache (.htaccess) with tools like
and see the complaints about the too low expiration
Proposed resolution
- Set the ExpiresDefault to 1Y instead of 14D.
- Discuss and document special cases that should have a lower value, like #3079404: Document that .htaccess 301s get the ExpiresDefault value of 2 weeks instead of the Drupal value
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
The root ".htaccess" file now has an increased "ExpiresDefault" value of one year. The value got increased to one year
Reason being, the recommendation by both Google Pagespeed and GTMetrix to increase the cache policy to one year for static files.