Mainio MinCo: free add-on for Minifying & Combining static assets
Permalink 2 users found helpful
Hi all!
Because of few clients some times keep asking to minify & combine static assets, I created a simple tool for that purpose available in the gitgub:
https://github.com/ahukkanen/c5_mainio_minco...
It's absolutely free and MIT-licensed. It's based on the minification libraries of this project:https://github.com/mrclay/minify...
Please note that this is HIGHLY EXPERIMENTAL at the moment and probably applying it into your theme will not give you any performance boost.
However, this is quite handy tool if you need to combine a bunch of JS/CSS files and serve them from one static file. It can actually do the work for you by automatically combining the files and re-writing your theme files where you've called the minco actions.
The readme-file in the github tells you how to use it and a bit of how it works as well.
Hopefully this will help someone else as well!
As said, this is highly experimental and I would not expect this to work in 100% of the situations at this point but a fair amount of work has been put into it already. If you notice something not working, etc. feel free to report the issues in this thread :)
Antti / Mainio
EDIT:
Developer note: combining EVERYTHING might also hit you back, especially if you have big JS/CSS files such as cufón font files (js). You should never try to combine these together. Other note is that if you try to combine the js/css added in <?php Loader::element('header_required') ?>, you will probably break your site (just saying, I've tested it works great with default concrete5 installation but probably if you have add-ons & customization, this will probably break your site).
Because of few clients some times keep asking to minify & combine static assets, I created a simple tool for that purpose available in the gitgub:
https://github.com/ahukkanen/c5_mainio_minco...
It's absolutely free and MIT-licensed. It's based on the minification libraries of this project:https://github.com/mrclay/minify...
Please note that this is HIGHLY EXPERIMENTAL at the moment and probably applying it into your theme will not give you any performance boost.
However, this is quite handy tool if you need to combine a bunch of JS/CSS files and serve them from one static file. It can actually do the work for you by automatically combining the files and re-writing your theme files where you've called the minco actions.
The readme-file in the github tells you how to use it and a bit of how it works as well.
Hopefully this will help someone else as well!
As said, this is highly experimental and I would not expect this to work in 100% of the situations at this point but a fair amount of work has been put into it already. If you notice something not working, etc. feel free to report the issues in this thread :)
Antti / Mainio
EDIT:
Developer note: combining EVERYTHING might also hit you back, especially if you have big JS/CSS files such as cufón font files (js). You should never try to combine these together. Other note is that if you try to combine the js/css added in <?php Loader::element('header_required') ?>, you will probably break your site (just saying, I've tested it works great with default concrete5 installation but probably if you have add-ons & customization, this will probably break your site).
Hi Antti, following our conversation, here goes a bit of feedback from this.
So far the only thing that breaks in the live site im using for this tests his image paths in css.
Im usinghttp://resposta-framework.concrete5-labs.com... to test it out, and quite happy with it, think that someone with a bit more knowledge (jordanlev) cough... (core T) cough... (mnkras) could clear out what might be wrong here.
Personally belive this would be a great adition to concrete5, as it's my tool of choice for almost all my projects and since miser been looking for a solution for this, your aproach pretty much nails it!!
So far the only thing that breaks in the live site im using for this tests his image paths in css.
Im usinghttp://resposta-framework.concrete5-labs.com... to test it out, and quite happy with it, think that someone with a bit more knowledge (jordanlev) cough... (core T) cough... (mnkras) could clear out what might be wrong here.
Personally belive this would be a great adition to concrete5, as it's my tool of choice for almost all my projects and since miser been looking for a solution for this, your aproach pretty much nails it!!
Post some screenshots if needed!
Yeah, I actually know what's wrong there: it doesn't change the image paths. After downloading each of the CSS files, it should do a regexp search for "url(anything_here)" strings and replace the paths with correct ones.
Thanks for the feedback, the project will continue to evolve!
Thanks for the feedback, the project will continue to evolve!
Heya,
I've been meaning to put this in use for like 2 months now. Never got quite around it since it didn't work out of the box when I initially tried it...
Anyway got some "spear" time at hands today so I thought I'd give it a spin...
I'm actually quite embarrassed to admit that it took me a while to figure out that the package folder and controller name doesn't match so either one needs to be renamed.
After sorting that out I actually had my hopes up that this will be painless road to victory. But oh boy was I wrong with that one. It took some digging to find out that the css and js files are fetched via file_get_contents() (oh why!?), so you're kinda required to use getStyleSheet() method. And that is one thing I never got into the habit of using.
Next problem was with DIR_TMP constant... I'm not sure is that some legacy constant or some inside joke but defaulting to that didn't quite rock my boat so I replaced the MINICO_RESOURCES_SAVE_DIR definition on controller with:
Further messing around has yet to yield any results but I've got a hunch that I'm getting there.
But oh boy did I laugh when I saw the "1min max" on this thread. Maybe its just me but the 1min max limit did kinda slip out of my hands like 60minutes ago =D. And I have yet to see any minified or combined css markup. bah.
Anyway thanks for the package (I guess)...
I've been meaning to put this in use for like 2 months now. Never got quite around it since it didn't work out of the box when I initially tried it...
Anyway got some "spear" time at hands today so I thought I'd give it a spin...
I'm actually quite embarrassed to admit that it took me a while to figure out that the package folder and controller name doesn't match so either one needs to be renamed.
After sorting that out I actually had my hopes up that this will be painless road to victory. But oh boy was I wrong with that one. It took some digging to find out that the css and js files are fetched via file_get_contents() (oh why!?), so you're kinda required to use getStyleSheet() method. And that is one thing I never got into the habit of using.
Next problem was with DIR_TMP constant... I'm not sure is that some legacy constant or some inside joke but defaulting to that didn't quite rock my boat so I replaced the MINICO_RESOURCES_SAVE_DIR definition on controller with:
Further messing around has yet to yield any results but I've got a hunch that I'm getting there.
But oh boy did I laugh when I saw the "1min max" on this thread. Maybe its just me but the 1min max limit did kinda slip out of my hands like 60minutes ago =D. And I have yet to see any minified or combined css markup. bah.
Anyway thanks for the package (I guess)...
Yeah, no problems bro.
This was initially put here at the time of 5.5.something and hasn't been updated since. At that time I believe it worked ok with about 1min setup (with the current c5 version back then).
The github is really there for doing some further work and contributing. I personally haven't put that much time into it since I put it to github. I hoped there would've been people trying it out to reveal issues in it at that time.
Maybe I'll take another dig at some point to resolve the few issues I've heard of and make it work with the latest c5 version.
On my part this has been only used to automatically minify the JS/CSS files, haven't really used it in the "automatic mode" (meaning it would work automatically with every request made to your site) it also supports because it would require a lot of work.
In the initial thread, I'm not sure whether you noticed the uppercased words: "HIGHLY EXPERIMENTAL". So it was in highly experimental mode in March, no feedback and no further work on it, guess where it's now? Well, it's still highly experimental.
Thanks for your feedback! (I guess)...
Antti / Mainio
This was initially put here at the time of 5.5.something and hasn't been updated since. At that time I believe it worked ok with about 1min setup (with the current c5 version back then).
The github is really there for doing some further work and contributing. I personally haven't put that much time into it since I put it to github. I hoped there would've been people trying it out to reveal issues in it at that time.
Maybe I'll take another dig at some point to resolve the few issues I've heard of and make it work with the latest c5 version.
On my part this has been only used to automatically minify the JS/CSS files, haven't really used it in the "automatic mode" (meaning it would work automatically with every request made to your site) it also supports because it would require a lot of work.
In the initial thread, I'm not sure whether you noticed the uppercased words: "HIGHLY EXPERIMENTAL". So it was in highly experimental mode in March, no feedback and no further work on it, guess where it's now? Well, it's still highly experimental.
Thanks for your feedback! (I guess)...
Antti / Mainio
Inspired by you decided to give it a shot with a 5.6.0.1 site. Copied the package to the packages directory, renamed it, applied your DIR_TMP fix, put the required Minco-block specifying functions to theme and it worked ok.
I'm not sure how you managed to put 1h+ to this but I did this in less than 5 mins (ok, maybe the 1min is a bit misleading).
I also pushed the DIR_TMP fix to github, thanks for reporting that!
There are still issues with the image path etc. but I believe they could also be fixed quite easily.
Best,
Antti
I'm not sure how you managed to put 1h+ to this but I did this in less than 5 mins (ok, maybe the 1min is a bit misleading).
I also pushed the DIR_TMP fix to github, thanks for reporting that!
There are still issues with the image path etc. but I believe they could also be fixed quite easily.
Best,
Antti
Nice response time there buddy !
Yeah well the setup was done in like 3 mins, the rest of the time went figuring out the ways you have done things and desperately trying to find the reason why it actually didn't work.
Put up a new 5.6.0.2 installation to see whether any custom stuff interfered with this functionality (which I highly doubted to begin with). Once again with no luck.
Turns out the mrclay's minify lib has some funky behavior with userdirs and it somehow tries to load resources from the actual server root. So setting up a virtual host to the current c5 installation folder did the trick... That indeed is some messed up sh*t. Should probably figure out why it does that but I think that time is better spent elsewhere...
Right, so now i need to figure out a way to pass css and js from page controllers to this... Good times :).
Will be adding pull requests if I happen to encounter some further problems.
But yeah, kudos for this. looking real good now.
Yeah well the setup was done in like 3 mins, the rest of the time went figuring out the ways you have done things and desperately trying to find the reason why it actually didn't work.
Put up a new 5.6.0.2 installation to see whether any custom stuff interfered with this functionality (which I highly doubted to begin with). Once again with no luck.
Turns out the mrclay's minify lib has some funky behavior with userdirs and it somehow tries to load resources from the actual server root. So setting up a virtual host to the current c5 installation folder did the trick... That indeed is some messed up sh*t. Should probably figure out why it does that but I think that time is better spent elsewhere...
Right, so now i need to figure out a way to pass css and js from page controllers to this... Good times :).
Will be adding pull requests if I happen to encounter some further problems.
But yeah, kudos for this. looking real good now.
Ok, thanks for the information.
And yes, if I can remember correctly, the minify library uses relative paths in its inclusions, so basically the minify location has to be defined in the PHP include_path. But I wouldn't expect this to break anything since Zend libraries do exactly the same thing in conrete5 core.
If you have some additional information, feel free to post it here as well!
Antti
And yes, if I can remember correctly, the minify library uses relative paths in its inclusions, so basically the minify location has to be defined in the PHP include_path. But I wouldn't expect this to break anything since Zend libraries do exactly the same thing in conrete5 core.
If you have some additional information, feel free to post it here as well!
Antti
The basic purpose of this add-on is to really save time in the minification/optimization process of the site.
The whole idea was to offer a tool that would automatically go through the concrete5 generated js/css urls that are some times served from /index.php/tools/... URLs. Combining and minifying those files would usually mean going through all of those URLs and first saving the generated output of all the files into a combined one. After that, minifying that file manually with some external tool.
Guess what, with this add-on this all only takes you 1min max. :)
So, any site optimizers out there willing to give this a shot? It would be greatly appreciated!
Antti