Last active
February 4, 2022 19:35
-
-
Save tdtgit/b0ae2200e3adfe8a54ad2b879d7c7533 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 | |
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