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

Minify JS

Hi, new with PHALCON,

Trying to minify some js, code below:

public function fichaAction() {

  $this->assets
              ->addJs('./../js/jquery-1.11.2.js')
              ->addJs('../../js/jquery.validate.min.js')
              ->addJs('../../js/infodiv.js')
              ->addJs('../../js/jquery.imageZoom.js')
              ->addJs('../../js/JQueryValidationProductPage.js')
              ->addJs('../../js/popup-window.js')
              ->addJs('../../js/product2scjs')
              ->addJs('../../js/productpage.js')
              ->addJs('../../js/tabber.js')
              ->addFilter(new Phalcon\Assets\Filters\Jsmin());

I'm getting the error: Call to undefined method Phalcon\Assets\Manager::addFilter()

When I use without the addFilter(new Phalcon\Assets\Filters\Jsmin()), everything goes ok, but no minify, offcourse. All the examples use the addFilter, but when I look at the documentation, of the Phalcon\Assets\Manager there is no addFilter method.

Using PHALCON 1.3.4 on Windows

Thank you

You need to create a collection first.

$this->assets->collection('js')
->addJs('./../js/jquery-1.11.2.js')
->addJs('../../js/jquery.validate.min.js')
->addJs('../../js/infodiv.js')
->join(true)
->setTargetPath($pathToCompiled)
->setTargetUri($pathToCompiled)
->addFilter(new Phalcon\Assets\Filters\Jsmin());

//then in volt:
{{ assets.outputJs() }}


1.6k

Look like it's working, now I have the error PhalconException: Non-free jsminifier not available ???

You need to create a collection first.

$this->assets->collection('js')
->addJs('./../js/jquery-1.11.2.js')
->addJs('../../js/jquery.validate.min.js')
->addJs('../../js/infodiv.js')
->join(true)
->setTargetPath($pathToCompiled)
->setTargetUri($pathToCompiled)
->addFilter(new Phalcon\Assets\Filters\Jsmin());

//then in volt:
{{ assets.outputJs() }}


1.6k
Accepted
answer

Thank you, that is the problem.

No another problem is tha I have the windows DLL, I have been reading and complie PHALCON in windows it is another level :)

Hi,

you have to recompile phalcon: https://forum.phalcon.io/discussion/4212/minify-assets-error