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

Prefix in Phalcon\Assets

Hi, Is there any way to get domain prefix for minified assets?

Following to https://docs.phalcon.io/en/latest/reference/assets.html#prefixes:

$this->assets
            ->collection('jsHeader')
            ->setPrefix('https://cdn.example.com/')
            ->setLocal(false)
            ->addJs('jquery.min.js'); 

will produce:

<script src="https://cdn.example.com/jquery.min.js" type="text/javascript"></script>

But if we want to get minified version of JS:

$this->assets->collection('jsFooter')
            ->setLocal(true)
            ->join(true)
            ->setPrefix('https://cdn.example.com/')
            ->setTargetUri('header.js')
            ->addFilter(new Phalcon\Assets\Filters\Jsmin())
            ->addJs('jquery.min.js'); 

we will get:

<script src="/https://cdn.example.com/header.js" type="text/javascript"></script>

(with / on beginning of url). So my question is: is there any way to remove slash from url?

Do ->addJs('jquery.min.js', false), or, do ->setLocal(false) like you had it in the previous example.

edited Oct '14

Yes, i'm sorry for wrong example. So, correct is this:

$this->assets->collection('jsFooter')
            ->setLocal(false)
            ->join(true)
            ->setPrefix('https://cdn.example.com/')
            ->setSourcePath($JsDir.$this->config->assets->srcDir)
            ->setTargetPath($JsDir.'header.js')
            ->setTargetUri('header.js')
            ->addFilter(new Phalcon\Assets\Filters\Jsmin())
            ->addJs('jquery.min.js');

And I get this:

<script src="/https://cdn.example.com/header.js" type="text/javascript"></script>

But if I will remove line with Jsmin filter, I get the correct link. But I need one file, not multiple.

<script src="https://cdn.example.com/jquery.min.js" type="text/javascript"></script>