We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PRevent generating Assets after page reload

Hi.

The problem is that minified files always regenerating after page reloaded. How can i prevent this until my minified content actually changed?


        $di->set('assets', function() use ($config) {
            $assets = new \Phalcon\Assets\Manager();
            $assets
                ->addJs('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false)
                ->addJs('//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js', false);
            $assets
                ->collection('headerCss')
                ->addCss('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', false, false)
                ->addCss('https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', false, false)
                ->addCss('https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', false, false)
                ->addCss($config->application->backendAssets.'/plugins/jvectormap/jquery-jvectormap-1.2.2.css', true)
                ->setTargetPath($config->application->documentRoot.'/assets/css/css.minified.backend.css')
                ->setTargetUri('p/assets/css/css.minified.backend.css')
                ->join(true)
                ->addFilter(new \Phalcon\Assets\Filters\Cssmin())
            ;
            return $assets;
        });


85.5k
edited Oct '15

https://github.com/phalcon/cphalcon/issues/549 it says there are functions like

compileAlways()
setTargetPath()

but i dont see them in latest docs, neighter in source code.

But never the less i dont think there was ever functionality to watch for changes, you should use gulp / grunt

edited Oct '15

Well i implemented In pretty simple way - in view i just have:

{% if request.hasQuery("flush") %}
{{ assets.outputJs("js") }}
{% else %}
<script src="/js/production.js"></script>
{% endif %}

You have to add ?flush - then all js will be regenerated and mindified again. If there are no ?flush its loading production.js which is my genrerated file from assets.outputJs.



12.2k
edited Oct '15

https://github.com/phalcon/cphalcon/issues/549 it says there are functions like

compileAlways()
setTargetPath()

but i dont see them in latest docs, neighter in source code.

But never the less i dont think there was ever functionality to watch for changes, you should use gulp / grunt

Yeahh... A bit old thread. Thanks for pointing. I do not want use gulp/grunt because I do not use complex JS in the project, where that can be used.

Well i implemented In pretty simple way - in view i just have:

{% if request.hasQuery("flush") %}
{{ assets.outputJs("js") }}
{% else %}
<script src="/js/production.js"></script>
{% endif %}

You have to add ?flush - then all js will be regenerated and mindified again. If there are no ?flush its loading production.js which is my genrerated file from assets.outputJs.

So simple and abvious. Thanks for the pointing. )