Non-blocking Asynchronous wp_enqueue_script
Wp_enqueue_script already has an argument that lets you move scripts to the bottom, so why not an option for async?
For anyone who needs this, there's a dirty hack from @toscho on the WordPress Stackexchange:
I am reading...
Since Version 4.1 a new filter has been introduced that finally provides a less painful solution to add async or defer attributes...
Installed the plugin, seems to be working - although PSI now reckons head.js is blocking ? correct ? should I expect this ?
Got the same error here when downloading and using that plugin. No idea if it will be fixed, but a core implementation would be the way around..
@Phil The solution in the link worked. But instead of the js handle, had to mention the actual js name. It added the "async" attribute to the js script tag.
Thank you so much for the plugin! It worked for me.
For those who prefer a non-plugin solution, this guy's post / code is working perfectly for me:
Keep in mind that async/defered will not work if your JS files have dependencies (ie: a jquery plugin needs jquery to be loaded first). The plugin I wrote could use some modernization (ie: determine if it can run pure async without doing head.js).
Though nowadays, minimizing all of your scripts into a single file or even embedding directly into your page can be more performant than going async.
RSS feed for this topic
You must log in to post.