Packing CSS and JS to one file is essential in building large apps, currently the only way is to use extensions. There are a lot of extensions that try to solve this, but they are always cumbersome to use, forcing you to hardcode the filenames or folders, overwriting core ClientScript class or making you use a custom method when publishing assets like Yii::app()->clientScript->minifyAsssets(‘myfile.js’);
I think packing should be in the core. So by supplying a ‘minify’ flag to Clientscript in config, all assets that are registered should be packed to one file.
Compressing the files is another story, since there are many different libraries available, it’s better to leave that part out of the core. Create some callback where the packed JS/CSS is supplied, so the user can do anything he wants with it before it is saved.
it seems that it is good to pack CSS and JS to one file, but please let me say sth.
as we know, the browser can cache the css and js file, not to load them in ever request, right?
let say we have there page, a.html, b.html, in a.html, we will include global.css, a.css, in b.html, we will include global.css, b.css, when packing the css to one file in a.html and b.html, the browser have to load the same content of global.css, right?
so, i think it is not good to pack css or js to one file.
The problem isn’t the file size, it’s the amount of requests. If you use a lot of external plugins and core scripts, you can get like 20 or more assets, each of them is a request that is queued and has to be DNS resolved. This adds up quickly.
I really like the way Drupal or Magento do it, just hit a checkbox and everything is packed into one file. This should work for Yii also.
That makes more sense than the "set a flag" suggestions above. Assetic looks like it covers about the set of functions needed.
Asset handling of big projects requires design. Fully automated compiling, combining and compression produces a thoroughly sub-optimal set of downloads.
Yii’s CClientScript and CAssetManager are fine for small projects where you need to get it done quickly. The “set a flag” for combination/compression would be valuable only in those same projects.
Agreed, therefore I suggested to only combine the files, and to allow the user to easily get the combined source, so extensions could hook into it and do whatever they want with it.
I don’t see the problem of Yii taking care of combining, since the location of the page (pos, head, ready) and the order of the files can be defined already, I don’t see what additional configuration you would need for combining.
I’ve done some large projects in Magento and Drupal and automatically combining worked like a charm, so the concept would work. Of course , Yii is still a framework so you’re free to not use the automatic combining and stick to some custom build solution that fits your project needs.
Assetic is an asset pipeline framework. It can be used to concatenate, minify, write assets in other languages such as CoffeScript, Sass. Assets will probably fall into three categories: javascripts, stylesheets, and images.
As for built-in asset manager, I think it’s just asset publisher, and as the result we can find a lot of extensions to work with assets.
Hope you are aware of the new Yii 2.0 version currently in development (nearing beta)? The version that is available for production release is Yii 1.1.14 (which possibly should be replaced by Yii 2.0 not far in future).
This forum is for [size="4"]Yii 2.0[/size] related discussions.