-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add Cache-control: immutable #7904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@MorrisJobke @nickvergessen @ChristophWurst @skjnldsv how do you all feel about this? It would basically omit refetching of the files if the browser supports it (most new ones do) if the hash doesn't change. Personally I don't really care that much as we cache them for a day now already. And re validating is done based on Etag. This would just be another optimization in that direction. |
|
I'm in, seems like the proper way to do it. But yes, we override the cache by switching the hash in updates so we should be clear here :) |
|
Ok then let me pick this up later today so we can get it in :) |
|
So second question. do we want different behaviour in debug mode? Currently we did not and it was still cached for a day. Which seems long. We could also switch to this by default. Less code paths is less things that can do 💥. |
|
@skjnldsv Could you give me an overview of how changes are detected? because I doubt that we are looking for the mtime for all involved files on every request, right? |
|
@MorrisJobke the hash is generated from the appversion it is part of. We could check the mtime (the SCSSCacher has all this info). But of course that would kind of kill performance. Maybe it is best to have guidelines
Note that this PR just changes the duration. Not the way things work. Right now people can also have outdated files on their dev instances for a day if they don't force refresh ;) |
|
Ah better idea. We could just generate a random hash when debug mode is set? Sure it sucks speed wise. But will work all the time. |
|
Ok let me convert this jsut to always use immutable. And then we tackle the other problems some other way. My reasoning:
|
Codecov Report
@@ Coverage Diff @@
## master #7904 +/- ##
=========================================
Coverage ? 51.86%
Complexity ? 25377
=========================================
Files ? 1608
Lines ? 95178
Branches ? 1377
=========================================
Hits ? 49366
Misses ? 45812
Partials ? 0
|
|
We have #7244 So just tell the browser to do aggressive caching. In debug mode you don't request those files anyway and just fetch the plain files. Ready for review! |
core/Controller/CssController.php
Outdated
| } | ||
| $response->cacheFor(86400); | ||
|
|
||
| $ttl = 365000000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really ... just roughly 41667 years 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe set it to a year: 8760 and until then the instance is updated anyways. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong - as this is seconds it is only a bit over 11,5 years
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was is used in all the example of the immutable object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we lower it to 1 year?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I mean it doesn't really make a difference. But as you wish 😉
core/Controller/JsController.php
Outdated
| } | ||
| $response->cacheFor(86400); | ||
|
|
||
| $ttl = 365000000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
MorrisJobke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍 I tested with and without debug mode and both have the same behavior. Beside that the cache now needs to be cleared (or the apps version should be updated) if you want to test new (S)CSS/JS for example.
|
@MorrisJobke well before we also said (without debug mode) cache this for 24 hours. But I guess if you are actively developping you should hard refresh anyways. As I have seen browsers already honour our 24h caching. |
Sure :) Was just a clarification comment. |
Cache generated CSS forever! Also cache combined JS forever Fix tests Signed-off-by: Roeland Jago Douma <[email protected]>
ChristophWurst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me
Fixes #7224
If not in debug mode we basically cache the CSS for ever ;) Else we fall back to the default (1 day) in debug mode.
Most modern browsers support this. And on upgrade we have a cache buster. basically it is just telling supported browsers this will not change.
Todo: