-
-
Save RomioDiver/1beb169d7e1ffdc59cdae934080a0b5c to your computer and use it in GitHub Desktop.
HTTP/2 Push CSS/JS with Autoptimize WordPress's plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* * Plugin Name: Autoptimize PUSH | |
* */ | |
add_filter('autoptimize_filter_cache_getname', 'pushAOFiles'); | |
function pushAOFiles($in) { | |
$pushType = substr($in, strrpos($in, ".") + 1) === "js" ? "script" : "style"; | |
// Do not push CSS files if it is already inline. | |
//if ($pushType == "style" && ((bool)get_option("autoptimize_css_inline", true))) return; | |
header('Link: <' . $in . '>; rel=preload; as=' . $pushType, false); | |
return $in; | |
} | |
add_filter('autoptimize_filter_js_exclude', 'pushJQuery'); | |
function pushJQuery($in) { | |
if (strpos($in, "js/jquery/jquery.js") !== false) { | |
$jQurl = includes_url("js/jquery/jquery.js"); | |
header('Link: <' . $jQurl . '>; rel=preload; as=script', false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment