Yii Framework Forum: Minifying assets - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Minifying assets

#1 User is offline   wisp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 192
  • Joined: 04-February 11

Posted 01 July 2012 - 12:16 PM

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.
4

#2 User is offline   Davidhhuan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 08-September 09

Posted 05 July 2012 - 12:26 AM

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.
no pain, no gain...

My Blog : http://cnblogs.com/davidhhuan
My website: http://sharefamily.net/
0

#3 User is offline   Hyprion 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 07-October 09
  • Location:Netherlands

Posted 05 July 2012 - 01:32 AM

@Davidhhuan: unless you pack global.css, a.css and b.css into one file and use that on both a.html and b.html

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.
0

#4 User is offline   wisp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 192
  • Joined: 04-February 11

Posted 05 July 2012 - 06:55 AM

View PostDavidhhuan, on 05 July 2012 - 12:26 AM, said:

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.
0

#5 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 10 July 2012 - 06:10 AM

If the core allows to set a flag in the clientScript component to combine multiple entries/files then everyone has their way.
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.
0

#6 User is offline   lightglitch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 05-January 10

Posted 12 July 2012 - 11:54 AM

You can always integrate https://github.com/k...llsmith/assetic with Yii.
0

#7 User is offline   fsb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 09-January 11

Posted 15 July 2012 - 10:28 AM

View Postlightglitch, on 12 July 2012 - 11:54 AM, said:

You can always integrate https://github.com/k...llsmith/assetic with Yii.

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.
Join the happiest place on Freenode: #yii
We've got a MrFisk the bot, hilarious banter and all kinds of other groovy stuff going on.
Comparison of Internet Relay Chat clients
Web IRC client
0

#8 User is offline   wisp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 192
  • Joined: 04-February 11

Posted 20 July 2012 - 01:41 PM

View Postfsb, on 15 July 2012 - 10:28 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.

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.
0

#9 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 11 March 2014 - 04:19 AM

Hey guys!

I'm working on extension that integrates Assetic into Yii. I'd like some feedback :)
0

#10 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 11 March 2014 - 06:52 AM

What are pros compared to built-in asset manager?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#11 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 12 March 2014 - 08:32 AM

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.
0

#12 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 12 March 2014 - 02:09 PM

Built-in asset manager in Yii2 is able to do all that.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#13 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 13 March 2014 - 04:28 AM

Give me an example how can I use different filters with built-in asset manager?
0

#14 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 13 March 2014 - 07:04 AM

https://github.com/y...asset-converter
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#15 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 13 March 2014 - 07:32 AM

Ok, but it is Yii2, not Yii.
0

#16 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 13 March 2014 - 08:35 AM

Well, we're in "General Discussions for Yii 2.0" subforum.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#17 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 14 March 2014 - 04:11 AM

Oops, this extension is related to Yii :)
0

#18 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 629
  • Joined: 29-August 12

Posted 14 March 2014 - 04:19 AM

View PostMr. T, on 14 March 2014 - 04:11 AM, said:

Oops, this extension is related to Yii :)

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.
0

#19 User is offline   Mr. T 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 11

Posted 14 March 2014 - 10:03 AM

Anyway, Yii will be used for a long time.
0

#20 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,782
  • Joined: 17-January 09
  • Location:Russia

Posted 17 March 2014 - 04:00 AM

Yep. Thanks for a useful extension.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users