Phalcon\Assets\Manager outputInlineJs() method. How it works?

According to my expectations, after I read oficial docs, this method should serve all js from my collection as single string with code enclosed in <script> tags, however in my case it just returns empty string for non empty collection.

outputJs() for the same collection returns <script> tags with paths to included files in src attributes, in other words works as expected.

By the way, do I understand correctly that this Assets minification, regenerated every time? is still true?



6.6k

Well, it appeared that this is normal behaviour of outputInlineJs()



1.6k

About the assets, well I don't know if it still regenerates every time, but I built a function to calculate the name for the minified import, works like this:

 private static function getDateName($resources, $importpath) {
    $ret = "";
    foreach ($resources as $resource) {
        $file = $importpath . str_replace("//", "/", $resource->getPath());
        if (filemtime($file) !== FALSE) {
            $ret .= date("YmdHis", filemtime($file)) . $file;
        }
    }
    return md5($ret);
}

$resources comes from $this->assets->collection(). So your filename for the minified will be the md5 of the concatenation of the modified dates of all your files. That way, you only hash once per request and if there's been no change, you can just use the file you have or if it's changed, you call your minify logic again and save the new minified file with that name.



6.6k

Nice solution for problem with assets regeneration, yes, it currently still exists, and it ruins some of client caching techniques. Thank you for sharing.

About the assets, well I don't know if it still regenerates every time, but I built a function to calculate the name for the minified import, works like this:

private static function getDateName($resources, $importpath) {
 $ret = "";
 foreach ($resources as $resource) {
     $file = $importpath . str_replace("//", "/", $resource->getPath());
     if (filemtime($file) !== FALSE) {
         $ret .= date("YmdHis", filemtime($file)) . $file;
     }
 }
 return md5($ret);

}

$resources comes from $this->assets->collection(). So your filename for the minified will be the md5 of the concatenation of the modified dates of all your files. That way, you only hash once per request and if there's been no change, you can just use the file you have or if it's changed, you call your minify logic again and save the new minified file with that name.