I want to load head js first and then all enqueued scripts into it’s function. Like so…
<script src=">/js/head.load.min.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
head.js("/path/to/jquery.js", "/google/analytics.js", "/js/site.js", function() {
// all done
});
</script>
How would I do this?
For those that don’t know HeadJS is the 2.30KB script that speeds up, simplifies and modernizes your site…
You should be forewarned that not all plugins/themes use enqueue. When I first started dealing with all the JavaScripts and CSS files outputed I just hooked into the enqueued files. This resulted in me only getting 2 out of 10 JavaScript files and 1 out of 3 CSS files.
Here is some quick PoCs. Neither tested but meant to put you in the right direction, if you can code. Once I get home I’ll whack together something more fitting and functional.
(Basically swiped most of the code from JS & CSS Script Optimizer)
Using WP Super Cache output buffering.
Here’s what I’m trying to do to integrate head.js:
i put this code in my template
functions.php
fileIt outputs something like this:
Notice that it also uses script labeling that could be really useful sometimes to identify what (and when) scripts are loaded.
You can also try out this plugin (or at least look at the code in it):
http://wordpress.org/extend/plugins/headjs-loader/
It does a regex on the output before it printed to the screen, so it works even with scripts that were not enqueued.
Here’s my solution for this. I’m using yepnope instead of head.js, but the theory’s pretty much the same.
https://wordpress.stackexchange.com/a/40325/9802
I hope it helps, and let me know if you have any comments on that other thread.