xwp / wp-dependency-minification

Dependency Minification plugin for WordPress
http://wordpress.org/plugins/dependency-minification/
52 stars 10 forks source link

Feature: Filter for adding scripts that would normally be inline into minification #53

Open Pypeline opened 10 years ago

Pypeline commented 10 years ago

I've been playing around with the plugin and needed a way to get some scripts that were inline (needing to use variables from php) into the concatenated/minified js file. Working on trying to get down to 1 js and 1css file. Anyway, I added a filter in the minify function just before stuff starts getting passed to the minify libraries.

looks like this:

$contents_for_each_dep = apply_filters( 'combine_inline_sources', $contents_for_each_dep, $type );

You'd want to check for $type depending on wether you're adding scripts or styles, and then you need to add a source name (URL seems irrelevant) and the js/css to the array of sources. This "inline" stuff wouldn't show up in the list of included dependency bundles but didn't seem like a big deal.

Just wondering if this is a feature that would be wanted in the plugin. Or if I missed something and there's already a better way to do this included! I can do a pull request if you're interested.

Pypeline commented 10 years ago

I guess I didn't consider instances where there's more than 1 minified and combined JS file, because this way would result in the extra scripts being added to each file put together by the plugin. I was focused on my use case of a single js file produced.

Still, might be something that can be done about that without much trouble.

shadyvb commented 10 years ago

I'm not sure if this would be a generically needed feature, since it'd invalidate the whole cached file if any inline script/css changes slightly. And I'm seeing little benefit of doing so, since for caching, this should be taken care of by page cache if activated, and for minification, there would be much less benefit since normally inline styles/scripts shouldn't be that big, also it'd be taken care of by HTML minifying/caching plugins.

Pypeline commented 10 years ago

Good point, thanks for the feedback.