Hi Frank,
I don't know if you're familiar with CloudFlare's Rocket Loader, but it adds their proprietary 'Rocket Script' tag to all scripts including those inline, thereby asynchronously loading them.
The problem is that Rocket Loader is applying the 'Rocket Script' tag to the script put out by AO's Inline and Defer CSS option (thereby asyncing it), and subsequently breaking the sites on which we are attempting to use both Rocket Loader and AO's Inline and Defer CSS.
There is a way to exclude certain scripts from Rocket Loader. In most situations, what we do to exclude certain scripts from being processed by Rocket Loader is as follows (in functions.php
):
function rocket_loader_attributes_start() {
ob_start();
}
function rocket_loader_attributes_end() {
$script_out = ob_get_clean();
$script_out = str_replace(
"type='text/javascript' src='{rocket-ignore}",
'data-cfasync="false"'." src='",
$script_out);
print $script_out;
}
function rocket_loader_attributes_mark($url) {
// Set up which scripts/strings to ignore
$ignore = array (
'script1.js'
);
//matches only the script file name
preg_match('/(.*)\?/', $url, $_url);
if (isset($_url[1]) && substr($_url[1], -3)=='.js') {
foreach($ignore as $s) {
if (strpos($_url[1], $s)!==false)
return "{rocket-ignore}$url";
}
return "$url' data-cfasync='true";
}
return "$url";
}
if (!is_admin()) {
add_filter( 'clean_url', 'rocket_loader_attributes_mark', 11, 1);
add_action( 'wp_print_scripts', 'rocket_loader_attributes_start');
add_action( 'print_head_scripts', 'rocket_loader_attributes_end');
}
The script put out by AO's Inline and Defer CSS option is a unique case, however, in that we can't quite figure out how to get CloudFlare's 'do not process' attribute (e.g. <script data-cfasync="false" src="/javascript.js"></script>) applied to it.
Rocket Loader tends to be able to async the un-asyncable (if I may invent a word), so we'd love to be able to use both it and AO's Inline and Defer CSS option at the same time.
Any ideas?
Best,
AJ
P.s. I realize the problem is not with AO per se, but since the problem is getting CloudFlare's attribute attached to a script generated by AO's Inline and Defer CSS option, I thought I'd poke your brain first since CloudFlare invariably considers such inquiries as outside of their purview.