Skip to content

Conversation

@rullzer
Copy link
Member

@rullzer rullzer commented Jan 16, 2018

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:

  • JS endpoint

@rullzer rullzer added this to the Nextcloud 14 milestone Jan 16, 2018
@rullzer
Copy link
Member Author

rullzer commented Jan 17, 2018

@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.

@skjnldsv
Copy link
Member

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 :)

@rullzer
Copy link
Member Author

rullzer commented Jan 18, 2018

Ok then let me pick this up later today so we can get it in :)

@rullzer
Copy link
Member Author

rullzer commented Jan 18, 2018

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 💥.

@MorrisJobke
Copy link
Member

@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?

@rullzer
Copy link
Member Author

rullzer commented Jan 18, 2018

@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

  • During development people will mostlikely force refresh anyways
  • Changes in css or js then require version bumps to propagate properly

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 ;)

@rullzer
Copy link
Member Author

rullzer commented Jan 18, 2018

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.

@rullzer
Copy link
Member Author

rullzer commented Jan 26, 2018

Ok let me convert this jsut to always use immutable. And then we tackle the other problems some other way.

My reasoning:

  • We already cache for a day
  • If you are having issues you will have refreshed properly already
  • Better to just tell the browser to cache like crazy ;)

@codecov
Copy link

codecov bot commented Mar 8, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@734cddf). Click here to learn what that means.
The diff coverage is 78.57%.

@@            Coverage Diff            @@
##             master    #7904   +/-   ##
=========================================
  Coverage          ?   51.86%           
  Complexity        ?    25377           
=========================================
  Files             ?     1608           
  Lines             ?    95178           
  Branches          ?     1377           
=========================================
  Hits              ?    49366           
  Misses            ?    45812           
  Partials          ?        0
Impacted Files Coverage Δ Complexity Δ
core/Controller/JsController.php 93.54% <100%> (ø) 7 <6> (?)
core/Controller/CssController.php 85.29% <66.66%> (ø) 7 <7> (?)

@rullzer
Copy link
Member Author

rullzer commented Mar 8, 2018

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!

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Mar 8, 2018
}
$response->cacheFor(86400);

$ttl = 365000000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number? 😉

Copy link
Member

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 😜

Copy link
Member

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. ;)

Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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 😉

}
$response->cacheFor(86400);

$ttl = 365000000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member

@MorrisJobke MorrisJobke left a 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.

@rullzer
Copy link
Member Author

rullzer commented Mar 8, 2018

@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.

@MorrisJobke
Copy link
Member

@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]>
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

@MorrisJobke MorrisJobke merged commit c8340ac into master Mar 21, 2018
@MorrisJobke MorrisJobke deleted the fix_7224 branch March 21, 2018 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants