MinQueue icon indicating copy to clipboard operation
MinQueue copied to clipboard

Option to enqueue minified scripts in the footer

Open einkoro opened this issue 11 years ago • 4 comments

Could we get an option to force the minified js to be enqueued in the footer? A lot of plugins do not enqueue in the footer by default and dequeueing and enqueuing them from the theme is a less than desirable work around.

einkoro avatar Feb 17 '14 19:02 einkoro

Yes, this would be really helpful because right now the only two options are 1. don't use this plugin and manually deregister & register JS, or 2. minify & concat, but don't get the benefits of footer JS.

djmadeira avatar Mar 06 '14 18:03 djmadeira

Thanks for your feedback.

The plugin loads the script in the location specified when enqueueing the script. My concern with forcing it to load in the footer, is that it could easily break stuff. I think the first thing people would do is move jQuery to the footer, and it would cause lots of support requests!

My suggestion would be to de-register, and re-register the JS, but continue to use the plugin to minify and concat. But watch out for JS errors.

I'll think about this, but perhaps there should be another plugin that allows you to modify where scripts are loaded?

mattheu avatar Mar 06 '14 18:03 mattheu

So it works to de-register and re-register, then have the plugin pick them up and concatenate? That's not so bad. Thanks!

What happens when some JS in a concat group is registered for the footer, and some for the header?

djmadeira avatar Mar 06 '14 18:03 djmadeira

Deregistering and registering works well enough until you find yourself in a child theme with a pile of dependancies. If the ability to add async/defer ever gains traction via additional parameters or a filter there really isn't any need to consider this. Then again its been four years running now: https://core.trac.wordpress.org/ticket/12009 https://core.trac.wordpress.org/ticket/22249

I suppose you could hack this into minqueue itself but its awfully dirty, subject to break whenever core gets around to handling it and probably better left to another plugin or the theme's functions.php for now. I'm using a mu-plugin with this at the moment:

function async_scripts($url) {
    if ( FALSE === strpos($url, '.js') ) { 
        return $url;
    }
    return "$url' async='async";
}
add_filter('clean_url', 'async_scripts', 11, 1);

einkoro avatar Mar 17 '14 00:03 einkoro