With the ExtendedClientScript you can combine / compress your used JS and CSS files, thus dramatically speed up page loading (or at least get a good speed grade in YSlow ).
The Extension is transparent, so no need for code changes. Just set it up in your config file. Almost all parameters can be set there.
For compression it will use JSMin and CssMin in extensions (included in zip).
Some (CSS) limitations:
Compressing CSS can have influence on your browser hacks.
Using relative urls in CSS can give issues.
Some tips:
Try to load the same scripts in the same order on every page, to make good use of the users’ browsercache, and to decrease the number of generated files.
You can exclude scripts in config, so some rarely used scripts can be excluded from compression.
Please tell me your findings!
Download here.
Aug. 31, 2011: New version 0.9.0, using CssMin ands several suggestions found in this thread. Also moved to extensions, with JsMin and CssMin in subdirs.
Yeah, there is no error this time and my application works fine. After I compare two HTML before/after enabling this extension, only one line differs. Is it expected?
Normally the above will add about 6 Javascript tags to your head section after calling render().
Without changing the above code, using ExtendedClientScript will automatically combine these files to one, and compress them with JSMin. After that you will have only one Javascript tag rendered in your head section.
This saves 5 HTTP roundtrips from client to server, and reduces the amount of data transferred to the client. This will give your pages a more responsive feel, and saves you a lot of data transfer on top.
Same goes for your CSS files registered with registerCssFile() (or registerCoreScript()). All separate CSS files will be combined, and CSSTidy will compress and correct your CSS.
For CSS files with relative url's (like jQuery UI themes) you need to convert the url's to be a relative to root url. I might add an additional routine to automatically convert the relative url's in a later version.
Thank you again for a nice extension. I have changed my application that can be acquired from the google code using your ExtendedClientScirpt extension. Karma++
BTW, when I tried to generate a module using a shell command such as '…/…/framework/yiic shell' under the application directory, I got an error as below.
Quote
<h1>PHP Error</h1>
<h3>Description</h3>
<p class="message">
filemtime(): stat failed for /assets/8e71a30/jquery.js</p>
Actually when I turned ExtendedClientScript configuration OFF in the config/main.php, there is no error. Does this error come from the ExtendedClientScript?
First off, thanks Maxximus for the great extension.
I made some slight modifications to support themes a little, with a sort of cascading file system. I'm not sure that this is the right place to do this, or even if its the "correct" way of doing it, as I have only been using Yii for a few days. I just figured I would share my code in the hopes that someone else finds it useful, or could point out its flaws.
Change in combineAndCompress:
Total combinAndCompress function:
What this does is allow you do use something like:
and it will use /assets/css/admin/main.css by default, but if a theme is enabled, and the file /themes/THEMENAME/assets/css/admin/main.css exists it will used the theme version instead.