Minifying assets
#1
Posted 01 July 2012 - 12:16 PM
POPULAR
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.
#2
Posted 05 July 2012 - 12:26 AM
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.
#3
Posted 05 July 2012 - 01:32 AM
But if a.css and b.css are very small, I usually don't bother putting them in seperate files anyway. So wrapping them would not benifit me.
But to minify the js files does have my vote, I use static js files more than generated js so this could make a difference for me.
#4
Posted 05 July 2012 - 06:55 AM
Davidhhuan, on 05 July 2012 - 12:26 AM, said:
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.
#5
Posted 10 July 2012 - 06:10 AM
Even the compression could be pre-made by supplying the compress-flag and a method to compress a file.
It's just a matter of selecting a compression package and overriding that one method.
#6
Posted 12 July 2012 - 11:54 AM
#7
Posted 15 July 2012 - 10:28 AM
lightglitch, on 12 July 2012 - 11:54 AM, said:
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.
#8
Posted 20 July 2012 - 01:41 PM
fsb, on 15 July 2012 - 10:28 AM, said:
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.
#10
Posted 11 March 2014 - 06:52 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#11
Posted 12 March 2014 - 08:32 AM
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.
#12
Posted 12 March 2014 - 02:09 PM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#13
Posted 13 March 2014 - 04:28 AM
#14
Posted 13 March 2014 - 07:04 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#16
Posted 13 March 2014 - 08:35 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#18
Posted 14 March 2014 - 04:19 AM
Mr. T, on 14 March 2014 - 04:11 AM, said:

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 Yii 2.0 related discussions.
#20
Posted 17 March 2014 - 04:00 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark