[EXTENSION] ExtendedClientScript - Reduce your page loading times
Posted 11 March 2009 - 06:46 PM
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.
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!
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.
Posted 12 March 2009 - 02:12 AM
Undefined offset: 0
Posted 12 March 2009 - 05:02 AM
No, my version is SVN 814.
I grepped the framework directory and found following.
Posted 12 March 2009 - 11:53 PM
Sorry, I was confused that you had attached your code to the article.
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?
! <link rel="stylesheet" type="text/css" href="/demos/yii-blogdemo-enhanced-extension/assets/4b0d6480/calendar.css" />
<title>blog - Post</title>
--- 22,28 ----
! <link rel="stylesheet" type="text/css" href="/demos/yii-blogdemo-enhanced-extension/assets/8e71a30/c_a9db2e66ee865f3702bb4da440f176f9.css" />
<title>blog - Post</title>
I am not sure what the condition of this extension is. Does this work with the code like this?
Posted 13 March 2009 - 03:50 AM
For example, in your controller (or view/layout) you have:
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.
Posted 23 March 2009 - 04:01 AM
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?
Posted 25 March 2009 - 06:52 PM
In a command line environment they are not available unfortunately. Currently I have no other solution than defining basePath and filePath in config.
I'm open for other suggestions.
Posted 26 March 2009 - 05:15 AM
I think ExtendedClientScript is for a performance purpose, how about to disable it when $_SERVER['DOCUMENT_ROOT'] is undefined?
Posted 26 March 2009 - 06:40 PM
if($_SERVER['DOCUMENT_ROOT']=='') define('CLI', true);
Second option in config/console.php:
$_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..';
Think the second is the nicest since it's only for cli, so no performance hit at all.
Found that the Yii class CFileHelper suffers too if you use that in your application, when using cli.
Posted 12 April 2009 - 02:27 PM
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.
Hopefully this is useful to someone.