-
Notifications
You must be signed in to change notification settings - Fork 345
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
make it unlikely that the client browser gets outdated js or css #907
Conversation
helpers/View.php
Outdated
* returns max mtime for file paths given in array | ||
* | ||
* @param filePaths array of file paths | ||
* @returns max mtime as int (unix timestamp) |
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.
Should be @return int
annotation.
helpers/View.php
Outdated
private function genMinified($type) { | ||
self::$staticmtime[$type] = self::maxmtime(\F3::get($type)); | ||
|
||
if ($type == 'js') { |
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.
Rather than 'js' and 'css', class constants should be created to decrease the chance of accidental mistypes. Since older versions of PHP do no support private constants, @internal
annotations should be used for now.
helpers/View.php
Outdated
* @param filePaths array of file paths | ||
* @returns max mtime as int (unix timestamp) | ||
*/ | ||
public static function maxmtime($filePaths) { |
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.
array
type hint should be added since it is supported since PHP 5.1: https://3v4l.org/U4Gq4
helpers/View.php
Outdated
foreach (\F3::get('css') as $file) { | ||
$css = $css . "\n" . $this->minifyCss(file_get_contents(\F3::get('BASEDIR') . '/' . $file)); | ||
// cleanup | ||
if ($builtSomething) { |
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.
Why not just use cache busting using query string?
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.
One disadvantage of cache busting using a query string is that it does not return a 404 for outdated content. But is saves the cleanup. Anyway, both may lower user support needs.
Website and |
This change makes the js and css generated to a file containing the max mtime of source material in its name. Therefore, each time the source js or css files are changed, a new file with a new name gets generated and referenced in the app. From the client browser's view, this is a new ressource that needs to get fetched regardless of the cache status of older css or js. The trade-off is that each request implies stat'ing each source material file. There is no notiecable time penalty in loading time.
71503d4
to
4ac4000
Compare
This change makes the js and css generated to a file containing the
max mtime of source material in its name. Therefore, each time the
source js or css files are changed, a new file with a new name gets
generated and referenced in the app. From the client browser's view,
this is a new ressource that needs to get fetched regardless of the
cache status of older css or js.
The trade-off is that each request implies stat'ing each source
material file. There is no notiecable time penalty in loading time.