Skip to content

Instantly share code, notes, and snippets.

frank goossens futtta

Block or report user

Report or block futtta

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@futtta
futtta / ao_css_defer.php
Last active Apr 22, 2019
experimental code snippet to have AO load full CSS later
View ao_css_defer.php
<?php
add_filter('autoptimize_filter_css_preload_onload','__return_empty_string');
add_filter('autoptimize_css_preload_polyfill','defer_iso_preload');
add_filter('autoptimize_html_after_minify','preload_to_aodeferload');
add_filter('autoptimize_filter_css_replacetag','inject_css_in_footer');
function defer_iso_preload() {
return '<script data-cfasync="false">!function(n){"use strict";n.loadCSS||(n.loadCSS=function(){});var o=loadCSS.relpreload={};o.bindMediaToggle=function(e){var t=e.media||"all";function a(){e.addEventListener?e.removeEventListener("load",a):e.attachEvent&&e.detachEvent("onload",a),e.setAttribute("onload",null),e.media=t}e.addEventListener?e.addEventListener("load",a):e.attachEvent&&e.attachEvent("onload",a),setTimeout(function(){e.rel="stylesheet",e.media="only x"}),setTimeout(a,3e3)},o.poly=function(){for(var e=n.document.getElementsByTagName("link"),t=0;t<e.length;t++){var a=e[t];"aodeferload"!==a.rel||"style"!==a.getAttribute("as")||a.getAttribute("data-loadcss")||(a.setAttribute("dat
@futtta
futtta / autoptimize_defer_inline_jquery.php
Last active Aug 12, 2019
POC to defer inline JS that requires jQuery
View autoptimize_defer_inline_jquery.php
<?php
add_action('plugins_loaded','ao_defer_inline_init');
function ao_defer_inline_init() {
if ( get_option('autoptimize_js_include_inline') != 'on' ) {
add_filter('autoptimize_html_after_minify','ao_defer_inline_jquery',10,1);
}
}
function ao_defer_inline_jquery( $in ) {
You can’t perform that action at this time.