Hi,
I use assets manager in order to download public libs from public CDN and minified personnal assets from my website.
To do that I create an initialize
method in ControllerBase
class, like this :
<?php
// ...
class ControllerBase extends Controller
{
public function initialize()
{
$this->assets->collection('headerCdn')
->addCss('//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', false, false);
$this->assets->collection('localCss')
->setTargetPath('css/style.min.css')
->setTargetUri('css/style.min.css')
->addCss('css/style.css')
->addFilter(new Phalcon\Assets\Filters\Cssmin());
$this->assets->collection('footerCdn')
->addJs('//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', false, false)
->addJs('//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', false, false);
$this->assets->collection('localJs')
->setTargetPath('js/script.min.js')
->setTargetUri('js/script.min.js')
->addJs('js/script.js')
->addFilter(new Phalcon\Assets\Filters\Jsmin());
}
// ...
}
Then rendering methods are called in main index.volt
file, like this :
<!DOCTYPE html>
<html>
<head>
{# ... #}
{{ assets.outputCss('headerCdn') }}
{{ assets.outputCss('localCss') }}
{# ... #}
</head>
<body>
{# ... #}
{{ assets.outputJs('footerCdn') }}
{{ assets.outputJs('localJs') }}
</body>
</html>
Now, while reloading the page, I note that script.min.js
and style.min.css
modification dates are always the same than the date when I reload my page (same date and same hour). I deduce that minified files are generated each time an HTTP call is performed and a page is rendered.
The ideal for me would be that the assets generation is performed only once and that the generated minified files are not overridden as long as they exist.
How could we do that ?