', ' AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript', ' AddOutputFilterByType DEFLATE application/javascript application/x-javascript application/json', ' AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml', ' AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf application/font-woff application/font-woff2', '', ); } /** * nginx config snippet for users to paste into their server block. */ public static function nginx_snippet() { return implode( "\n", array( 'gzip on;', 'gzip_vary on;', 'gzip_min_length 1024;', 'gzip_proxied any;', 'gzip_comp_level 6;', 'gzip_types', ' text/plain text/css text/xml text/javascript', ' application/javascript application/json application/xml', ' application/xml+rss application/xhtml+xml', ' image/svg+xml font/ttf font/otf application/font-woff application/font-woff2;', ) ); } /** * Returns true if the response we just received looks GZIP-encoded. * Result is cached in a transient for 1 hour because the probe makes a * full HTTP request to home_url() — too slow to run on every /status hit. */ public static function probe_active() { $cached = get_transient( 'xspeed_gzip_active' ); if ( false !== $cached ) { return '1' === $cached; } $res = wp_remote_get( home_url( '/' ), array( 'headers' => array( 'Accept-Encoding' => 'gzip' ), 'timeout' => 3, ) ); $active = false; if ( ! is_wp_error( $res ) ) { $enc = wp_remote_retrieve_header( $res, 'content-encoding' ); $active = is_string( $enc ) && false !== stripos( $enc, 'gzip' ); } set_transient( 'xspeed_gzip_active', $active ? '1' : '0', HOUR_IN_SECONDS ); return $active; } }