I really do not suggest you do this because the YUI JS compressor will be loaded every time a resource is requested. But this is one way to do it anyway.
Note that to simplify a simple example, I excluded the extra code to correctly determine your web root and the location of the jar file.
$path = $this->container->getParameter('kernel.root_dir'); $ac = new \Assetic\Asset\AssetCollection(array( new \Assetic\Asset\FileAsset($path . '/../src/WebBundle/Resources/public/js/jquery.longclick.js') ), array( new \Assetic\Filter\Yui\JsCompressorFilter($path . '/Resources/java/yuicompressor-2.4.7.jar') )); $compressJS = $ac->dump(); return new Response($compressJS, 200, array('Content-Type' => 'text/javascript'));
Also note: you are not limited to FileAsset () only. There are other classes such as StringAsset (), etc., so you can dynamically create content.
lifo
source share