With this extension you can transparently reduce page load times by combining and compressing the used Javascript and CSS files.
All parameters can be set in your main.php config. No need for altering your code, just set and forget.
Needs Yii 1.0.4/1.1.x or greater, and for compression JSMin and CSSTidy.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0.4/1.1.x or above
Installation ¶
Since version 0.9
- Extract the zip file under 'proctected/extensions'
- Add the following to your 'config/main.php':
// application components
'components'=>array(
....
'clientScript'=>array(
'class'=>'ext.ExtendedClientScript.ExtendedClientScript',
'combineCss'=>true,
'compressCss'=>true,
'combineJs'=>true,
'compressJs'=>true,
),
And you're set!
For more options see the comments in the file. To mention a few:
- excludeFiles: array with files not to be combined/compressed. Handy for some rarely used JS/CSS files.
- autoRefresh: If false, no check on filemtime() to speed up a bit more. Useful in production.
Change Log ¶
August 30, 2011: 0.9.0 ¶
- New version, using CssMin and JsMin (included). Several improvements of Sam included.
August 23, 2011: 0.4.1 ¶
- Automatic exclusion of remote files (JS as well as CSS), so you can use your CDN of choice. Thanks Kir!
- By popular demand: removal of DIRECTORY_SEPARATOR, changed to '/'
March 12, 2009 ¶
- Additional test to prevent E_ALL errors.
March 11, 2009 ¶
- Initial release.
CSS file handling need to be improved
The option "excludeFiles" does only work for JS files. CSS files getting combined/compressed even if listed in the option "excludeFiles".
Another improvement would be to exclude all files where the path points to a CDN.
csstidy too old
seems that csstidy is too old for php 5.3 :(
"Non-static method csstidy::is_important() should not be called statically, assuming $this from incompatible context" .. don't want to start debugging as it ends up with 6 hours and no result :)
Trying to find a good alternative...
DIRECTORY_SEPARATOR
DIRECTORY_SEPARATOR is - as the name says a directory separator, not a url separator. So it works well with linux and mac because the folder separator in urls matches the directory separator.
As windows uses the backslash \ creating a url with the constant DIRECTORY_SEPARATOR can't work anymore on windows virtual hosts.
So there definitely has to be a "/" instead of the constant DIRECTORY_SEPARATOR.
Update
Updated extension code
DIRECTORY_SEPARATOR
Same problem with DIRECTORY_SEPARATOR.
Great component
I have the same issue Boris did.
For me in line 221 does not make sense use DIRECTORY_SEPARATOR because this a URL separator and not a file separator.
You said: "It is also used in several other places in this extension".
This is just coincidence.
In my Windows XP DIRECTORY_SEPARATOR is '\' and in your tests maybe is LINUX. And linux maybe is '/' separator, just like URL separator which is '/'.
DIRECTORY_SEPARATOR
Thanks!
DIRECTORY_SEPARATOR is a predefined PHP constant, so that can't (shoudn't) be the real issue. It is also used in several other places in this extension.
BTW: Might be better to use the forum thread for this: [url=http://www.yiiframework.com/forum/index.php/topic,1091.0.html]forum discussion[/url]
Great job, is this a bug?
Hi,
it works fine for me. Great idea, no need to reinvent the wheel now ;-)
But can you please check the line 221 in the current revision of ExtendedClientScript
I think DIRECTORY_SEPARATOR is wrong, i did not work for me, it worked as i changed it to "/". How come? Idea?
Otherwise i got errors that resource could not be found...
Thanks,
Boris
DIRECTORY_SEPARATOR BUG AND RECOMMENDED
In the 221 line, you can not use DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR used in the URL is not correct, I agree this is a bug. In addition, can you turn the associated documents to be re-released, such as the pictures to use relative paths inside css file? I think this is necessary, css files are mapped to another file, the directory path has changed, the picture of the paths must be properly re-mapping.This is also can be done.
DIRECTORY_SEPARATOR not needed
DIRECTORY_SEPARATOR is not needed. As long as you use forward slashes (/) everywhere everything will work as intended.
All *nix systems use forward slashes (/) while windows use back slashes (). The good news is that Windows converts forward slashes (/) into back slashes () hence why you should only use forward slashes (/). It's been like this for ages and that's how i do it.
Facing a problem
Hi first of all thank you for this extension i have been using it for quite sometime now....just one problem...now whenever i use a widget from yii the images do not load when the compression is on...if i take the compression off it works fine...i checked the css which is calling the images and they are fine but once the compression happens the css file gets moved and so the path in the css does not work... how do i make it work..kindly help
Re: Facing a problem
deadmantfa: i posted patch for it at google code, here it is http://code.google.com/p/extendedclientscript/issues/detail?id=1
thank you Nafania
Thank u Nafania I shall check this out Tom and let u know how it goes. Cheers
Thank u
Thank you Nafania it worked like a charm....great work...cheers
Another server host
Could I set another server url for generated files like this: http://www.yiiframework.com/doc/api/1.1/CAssetManager#basePath-detail ?
Enhancements
I propose you to enhance some functionality of excluding css and js files:
public function renderHead(&$output) { .......... foreach ($this->cssFiles as $url => $media) { $file_arr = pathinfo($url); if (!empty($this->excludeCssFiles) && in_array($file_arr['basename'], $this->excludeCssFiles) || $this->isRemoteFile($url)) { // excluding files } else { $cssFiles[$media][$url] = $url; } } ......... }
And renderJs function:
private function renderJs($output, $pos) { ....... foreach ($jsFiles as &$fileName) { $file_arr = pathinfo($fileName); (!empty($this->excludeJsFiles) && in_array($file_arr['basename'], $this->excludeJsFiles) || $this->isRemoteFile($fileName)) AND $fileName = false; ....... }
After this enhances I can do this in my config:
'clientScript' => array( 'class' => 'application.extensions.ExtendedClientScript.ExtendedClientScript', 'combineCss' => true, 'compressCss' => true, 'combineJs' => true, 'compressJs' => true, 'excludeJsFiles' => array('jquery.min.js', 'jquery-ui.min.js', 'jquery-ui.css'), 'excludeCssFiles' => array('jquery-ui.css'), ),
include(JSMin.php) error
Hi,
Thank you for the extension.
Do you have an idea what can cause this error:
include(JSMin.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
?
It appears only if
'autoRefresh' => true,
For a quick fix I added
'import'=>array('ext.ExtendedClientScript.jsmin.JSMin' )
to config file.
Is it expected behavior?
Array to string conversion
Just started, installed and set the config.
I got: Array to string conversion in [...]/ExtendedClientScript.php on line 209
@Nathan - Re: Array to string conversion
In ExtendedClientScript.php, line 209, replace:
serialize($this->cssMinFilters . $this->cssMinPlugins)
With:
serialize($this->cssMinFilters) . serialize($this->cssMinPlugins)
pull request
@Rodrigo Coelho
I've published it on the github with your fix: https://github.com/kirs/extendedclientscript
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.