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 Drupal root .htaccess file now caches all files for 1 year instead of two weeks. This bring the value in line with industry standards.
Issue fork drupal-3311406
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyComment #3
anybodyI decided to use
ExpiresDefault "access plus 1 year"notation, as it's easier to read than the seconds syntax used before, but of course we can also use that.I think this is a lot more self-explaining.
Comment #5
anybodyComment #6
cilefen commentedThis is a behavioral change where nothing is actually “broken”.
Comment #7
anybodyThanks @cilefen you're right! Feature request is better here.
Comment #8
wim leersComment #9
anybodyHere's the patch to review, so we don't have to rebase this all the time ;)
#3159964: Improve example for https redirect in .htaccess fixed the same in the dropsolid_rocketship profile, so we're getting closer to RTBC as this was tested on many sites before.
Comment #10
anybodyNeeds a reroll, the .htaccess has been changed in the meantime, as it seems.
Comment #12
grevil commentedRebased!
Comment #13
anybodyThanks @Grevil. Having a closer look at the failing tests, 7 of them seem unrelated to me, but this one has to be fixed:
Comment #14
anybodyHere we go! :)
Comment #15
grevil commentedI think the "\n" will throw an error.
Comment #16
anybodyMuch traffic at 10.1.x-dev while I think the patch / MR itself is fine now. Should we better target 10.0.x for review?
Comment #17
anybodyComment #19
anybodyComment #20
anybodyComment #21
grevil commentedI don't know, creating separate merge requests and changing the version will just create chaos. Setting version back to 10.1.x.
Comment #23
grevil commentedComment #24
nod_test seem like one of the random failures, MR needs reroll
Comment #26
anybodyRerolled, thx. As this is a "tiny" (LOC) change, we should perhaps try to decide what to do here for not having to rebase this easy day? :)
Comment #27
nod_not sure I see any changes as to what happened previously but it might be a config issue on my end.
Comment #28
nod_might want to be more specific in what gets cached a year. usually it's for CSS/JS/images not redirects, that might be an issue to cache those for a year instead of 2 weeks.
also need change to the web.config file maybe?
Comment #29
anybodyThanks @_nod! Looking at #3054821: Include Cache-Control header on 301 redirects. and thinking about explicit rules per mime type I think we should keep this as-is and let the redirect do its own thing in the other issue.
Otherwise, this will end up for us in having to update the mime types for every new image type etc. - I don't thing that's a good thing.
For such an example see https://www.supertechcrew.com/htaccess-rules-security-cache-redirect/ > "Caching rules"
Do you agree?
Setting this back to "Needs review" for that reason. I still think the changes are good.
Comment #30
anybodyComment #31
smustgrave commentedSeems fine to me. lets see what the committers say.
Comment #32
nod_Looked at the other issue and I agree with #29, that makes sense to me RTBC +1
Comment #33
alexpottChanges to .htaccess need a release note and a CR because they can require users to make updates since this can be hand edited. See #2854817: Duplicate X-Content-Type-Options headers both with the value nosniff as an example of the things needed.
Comment #34
grevil commentedI created a CR draft here: https://www.drupal.org/node/3349094 and a release note snippet got added in the issue summary.
Please correct me if either the snippet, or the CR draft is incorrect, as I don't have enough insights.
Comment #35
smustgrave commentedTook a look at the change record and change makes sense. Examples of why the change happened should be useful to others.
Comment #36
alexpottCommitted 67357a3 and pushed to 10.1.x. Thanks!
Comment #38
alexpottDiscussed with @catch we agreed that js and image styles all have cache busting logic. This will change how long logos and favicons for. Even today if you change these it would be recommended to use a different file name because they are already cached for 2 weeks.
Comment #39
anybodyFunny question, I know. But should we backport this to Drupal 7? Also 14d there...
Comment #40
longwave@Anybody I would open a separate issue to discuss - D7 is somewhat more conservative around changes and the considerations there might be different. If someone was already affected by this on D7 they likely would have already made this change to their site; nobody should be building new sites on D7.
Comment #41
quietone commentedTweaked the release note snippet and changing tags.
Comment #43
quietone commentedChange record published.