This extension allows you to seamlessly minify and merge your CSS and JS files.
Tested on 1.1.9, should work on 1.1.*
20120507.1438 UTC+1
20120330.1039 UTC+1
20120327.1112 UTC+1
Extract the files to the corresponding directories, components/* into compontents/ and extensions/* into extensions/ then configure the config file as described below, now MinifyClientScript will do the rest. :) Please comment if you have comments/suggestions/questions.
Example main.php:
return array( ... 'components'=>array( ... 'clientScript'=>array( 'class'=>'application.components.MinifyClientScript', ), ... ), ... );
I have written a blog about minifying and merging CSS/JS, read more about it HERE.
Total 20 comments
POS_* aren't ignored anymore, and the files should no longer rebuild at every request.
huge, huge problem in the component part of this:
Lines 156-157:
Should be:
This was causing a 2 second time to first byte on my server because it generated the cached files every request.
its says the problem in components\MinifyClientScript.php line: 132
I can't seem to reproduce your error, but you could check whether the runtime/MinifyClientScript directory has been published properly, just look for the core-BIGHASHHERE.js file in the assets directory.
Extending CAssetManager could be a nice way to minify the code, but it would require you to recursively search the directory to find .css- and .js-files and it would not merge the files though (which MinifyClientScript also does). You could try and use JSMin and CssCompressor to extend CAssetManager.
ksangers,
Thanks for your quick reply, the 404 errors are not coming through now; however, the error "jQuery is not defined" is still an issue.
I cleaned the www/assets and www/protected/runtime/MinifyClientScript directories. Also to confirm components/MinifyClientScript.php line 132 is your updated version.
Current error is:
After running the application again: jquery exists in the runtime/MinifyClientScript under a hash file name. Anyone know a solution, something I'm missing?
What if you extended CAssetManager.php and replaced function publish(...) to pipe any .css or .js through minify ?
Could you check components/MinifyClientScript.php line 132 (at the end of minifyCss())? It should be:
and not:
Otherwise clearing the runtime and www/assets directories might help.
Hi!
Same as Jesse :
Plus, when I take a look in the file (wich actually exists), it is empty...
Cheers!
Thanks for the comments guys! I've updated the code and put it online. Let me know what you think of this version, especially what you don't like so I can fix it! :)
Hi, great extension you've made here!
I keep receiving this error:
etc
Obviously the assets are not being found. Perhaps the "%5C" is the problem??
I'm wondering if anyone else had a similar issue and knows the solution?
Just a small addition to this wonderful clientscript minimizer:
In order to make CClientScript chainable, please return the object:
public function registerScript() [ return parent::
public function registerCss() [ return parent::
(line 223/234/236)
I have updated the file to do the callback differently, could you test this? If it still does not work I would like to know what PHP version you are using so I can fix this better.
Hope this works :)
Your extensions give me this error :
"preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, 'self::cssReplaceCallback', to be a valid callback"
Where is the problem here?
Ok, thx for the update...
Yeah I noticed this, and fixed this. You got the crappy version really quick! (<5mins of me posting it)
I had the strpos(haystack, needle) wrong, I've already updated it. Sorry for the inconvenience.
Hi!
I found three error cases :
when calling this :
This occurs when the Yii-Debug-Toolbar extension tries to register its own scripts...
when calling this :
In this case, line 248 of MinifyClientScript.php should be :
I get the same error :
when calling this :
This occurs when calling a CJui widget. In my configuration main.php, I have :
Thanks again for your help.
Hello fleuryc,
I think I've fixed the problem (for themed files) now, could you test it?
Thanks
Thanks for the quick answer! When I simply use the default 'clientScript' component, all of my files are found and everything is OK. The problem seems to stem from the fact that my JS and CSS files are not where the ext expects them to be.
For instance : I call :
wich gives :
and in the rendered HTML :
where it should be :
It's all the same for the other files I try to register. And I realise that these files are not combined and minified...
Thx for helping. Cheers!
Is it possible that you have non-existing files in your clientScript->scriptFiles or clientScript->cssFiles?
could you post them (var_dump()-ed or something) to me so I can debug it if it's a bug in MinifyClientScript.
3) Consider the relocation and importing done!
Hi!
Very usefull ext! I was thinking of extending the clientScript component myself, but I'm kind of lazy, and sure other people do things better than just me.
Still, I installed and configured this ext as explained here, but some of the CSS and JS files can't be found (404 error), and when I dig into the assets, those files exist but are empty...
Any clue where that comes from?
Cheers
Leave a comment
Please login to leave your comment.