Append file modify time to asset urls.

This commit is contained in:
flash 2018-07-21 18:01:36 +02:00
parent 4be217db67
commit 7c1dd2ed7d
4 changed files with 27 additions and 6 deletions

View file

@ -64,6 +64,8 @@ class Application extends ApplicationBase
private $mailerInstance = null;
private $startupTime = 0;
/**
* Constructor, called by ApplicationBase::start() which also passes the arguments through.
* @param null|string $configFile
@ -71,6 +73,7 @@ class Application extends ApplicationBase
*/
public function __construct(?string $configFile = null, bool $debug = false)
{
$this->startupTime = microtime(true);
parent::__construct();
$this->debugMode = $debug;
$this->configInstance = new ConfigManager($configFile);
@ -82,6 +85,11 @@ class Application extends ApplicationBase
);
}
public function getTimeSinceStart(): float
{
return microtime(true) - $this->startupTime;
}
/**
* Gets instance of the config manager.
* @return ConfigManager
@ -287,6 +295,7 @@ class Application extends ApplicationBase
$this->templatingInstance->addFilter('colour_get_blue');
$this->templatingInstance->addFilter('parse_line');
$this->templatingInstance->addFilter('parse_text');
$this->templatingInstance->addFilter('asset_url');
$this->templatingInstance->addFunction('git_commit_hash');
$this->templatingInstance->addFunction('git_branch');

View file

@ -44,6 +44,17 @@ function check_mx_record(string $email): bool
return checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A');
}
function asset_url(string $path): string
{
$realPath = realpath(__DIR__ . '/public/' . $path);
if ($realPath === false) {
return $path;
}
return $path . '?' . filemtime($realPath);
}
function dechex_pad(int $value, int $padding = 2): string
{
return str_pad(dechex($value), $padding, '0', STR_PAD_LEFT);

View file

@ -4,8 +4,8 @@
<meta charset="utf-8">
<title>{{ globals.site_name|default('The') }} Broom Closet</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link href="/css/manage.css" rel="stylesheet">
<link href="/css/libraries.css" rel="stylesheet">
<link href="{{ '/css/manage.css'|asset_url }}" rel="stylesheet">
<link href="{{ '/css/libraries.css'|asset_url }}" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="manage">
@ -72,7 +72,7 @@
{% endif %}
</footer>
</div>
<script src="/js/libraries.js" charset="utf-8"></script>
<script src="{{ '/js/libraries.js'|asset_url }}" charset="utf-8"></script>
<script>
window.addEventListener('load', () => {
timeago().render(document.querySelectorAll('time'));

View file

@ -15,8 +15,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
{% include '@mio/_layout/meta.twig' %}
<link href="https://static.flash.moe/fonts/visitor/visitor1.css" rel="stylesheet">
<link href="/css/mio.css" rel="stylesheet">
<link href="/css/libraries.css" rel="stylesheet">
<link href="{{ '/css/mio.css'|asset_url }}" rel="stylesheet">
<link href="{{ '/css/libraries.css'|asset_url }}" rel="stylesheet">
</head>
<body class="mio">
<div class="mio__wrapper">
@ -72,6 +72,7 @@
# {{ ('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true))|html_link(git_commit_hash(), 'footer__copyright__link') }}
{% if query_count is defined %}
/ SQL Queries: {{ query_count|number_format }}
/ Took: {{ app.timeSinceStart|number_format(5) }} seconds
{% endif %}
</div>
@ -85,7 +86,7 @@
{% endautoescape %}
</footer>
</div>
<script src="/js/libraries.js" charset="utf-8"></script>
<script src="{{ '/js/libraries.js'|asset_url }}" charset="utf-8"></script>
<script>
window.addEventListener('load', () => {
timeago().render(document.querySelectorAll('time'));