asset_compress icon indicating copy to clipboard operation
asset_compress copied to clipboard

Should auto included javascript controller/view files be minifed?

Open tmazur opened this issue 12 years ago • 11 comments

I expected auto included js files to be minified according to the filters set up in asset_compress.ini. But the files that are included are not processed in any way. After looking at the code in AssetCompressHelper.php this is the intended behavior, but stands in contrast with the v0.5 changelog "Controller/view javascript files are now combined into minified asset automatically now.".

Am I missing something? Is there any way to automatically minify these files?

tmazur avatar Oct 30 '12 16:10 tmazur

They aren't automatically minified as that would require generating build file definitions for them or using the dynamic build files, which are not supported in the standard non debug deployment case.

markstory avatar Oct 30 '12 20:10 markstory

What I'm looking for is simply minifying those files. I was thinking about adding a setting in asset_compress.ini 'filter_autoincluded'. If this would be set to true, running a shell build command would search for .js files in /js/views/*, run them through the filters, and finally save the filtered version to the cache path(preserving the directory structure).

So for example for an unfiltered file /js/views/posts/index.js we would end up with a filtered version of that file in /cache_js/views/posts/index.js. The helper would check the setting, check if the minified version exists, if not fall back to original. Simple and it works. Would you be willing to pull in such a feature? Maybe you have a better idea?

tmazur avatar Oct 31 '12 12:10 tmazur

That seems like a reasonable way to do things. Having the build shell walk those directories and minify each file into a mirrored directory structure in the cachePath will be simple and makes sense to me.

markstory avatar Oct 31 '12 20:10 markstory

Hi. Was wondering if there was any news on this one, that's a feature I would be very interested in (especially if it could also support the $timestamp options). Thanks

sebastienbarre avatar Jul 01 '13 05:07 sebastienbarre

There hasn't been any change here. I don't personally use this feature. Getting the autoincluded scripts working with the filter system might be a bit awkward. If you would like to take a stab at it, please do.

markstory avatar Jul 01 '13 12:07 markstory

OK, thanks. I'll revisit this issue later, already took me a while to backport some of the recent changes on top of v0.5, we are still using CakePHP 1.3 here :) Thanks for this plugin, really helps.

sebastienbarre avatar Jul 01 '13 19:07 sebastienbarre

Welcome :) I think the dynamic build files needs to be rethought in general. I find having two ways to create builds is awkward but I've not yet come up with a good way to unify them. If you have any thoughts on how the dynamic build files could be improved let me know.

markstory avatar Jul 01 '13 20:07 markstory

@sebastienbarre Are you still interested in that feature? Maybe a PR with your proposed changes would speed things up and gets it merged in quicker.

dereuromark avatar Jul 17 '14 10:07 dereuromark

@dereuromark I still am, though the changes were proposed by @tmazur

sebastienbarre avatar Jul 17 '14 15:07 sebastienbarre

Ops ;) Well then the PR advice goes to him then.

dereuromark avatar Jul 17 '14 15:07 dereuromark

After looking into how this feature might be implemented, the required time overwhelmed me, and I put this on my 'todo some day far away' list. Anyway, if I find some spare time I will implement this feature and create a PR.

tmazur avatar Jul 17 '14 15:07 tmazur