  &lt;?php
/**
 * Plugin Name: COMAIN Speed Optimizer
 * Description: mu-plugin for page size optimization: defer non-critical CSS, async JS, remove query strings
 * Version: 1.0
 * Author: COMAIN Dev
 */

// 1. Remove query strings from static resources (improves caching)
add_filter(&#039;script_loader_src&#039;, &#039;comain_remove_query_strings&#039;, 15, 1);
add_filter(&#039;style_loader_src&#039;, &#039;comain_remove_query_strings&#039;, 15, 1);
function comain_remove_query_strings($src) {
    if (strpos($src, &#039;?ver=&#039;) !== false) {
        $src = remove_query_arg(&#039;ver&#039;, $src);
    }
    return $src;
}

// 2. Defer selected non-critical JS (exclude jQuery, WooCommerce cart)
add_filter(&#039;script_loader_tag&#039;, &#039;comain_defer_js&#039;, 10, 3);
function comain_defer_js($tag, $handle, $src) {
    $exclude = array(
        &#039;jquery&#039;, &#039;jquery-core&#039;, &#039;jquery-migrate&#039;,
        &#039;wc-cart-fragments&#039;, &#039;wc-add-to-cart&#039;,
    );
    if (in_array($handle, $exclude)) {
        return $tag;
    }
    // Defer all theme/plugin scripts except inline
    if (strpos($tag, &#039;src=&#039;) !== false &amp;&amp; strpos($tag, &#039;defer&#039;) === false) {
        return str_replace(&#039; src=&#039;, &#039; defer src=&#039;, $tag);
    }
    return $tag;
}

// 3. Disable emoji JS (saves ~15KB)
remove_action(&#039;wp_head&#039;, &#039;print_emoji_detection_script&#039;, 7);
remove_action(&#039;wp_print_styles&#039;, &#039;print_emoji_styles&#039;);

// 4. Disable oEmbed discovery (saves ~10KB)
remove_action(&#039;wp_head&#039;, &#039;rest_output_link_wp_head&#039;, 10);
remove_action(&#039;wp_head&#039;, &#039;wp_oembed_add_discovery_links&#039;);
remove_action(&#039;wp_head&#039;, &#039;wp_oembed_add_host_js&#039;);

// 5. Remove shortlink and WLW manifest
remove_action(&#039;wp_head&#039;, &#039;wlwmanifest_link&#039;);
remove_action(&#039;wp_head&#039;, &#039;rsd_link&#039;);
remove_action(&#039;wp_head&#039;, &#039;wp_shortlink_wp_head&#039;);

// 6. Disable WooCommerce generic styles where not needed
add_filter(&#039;woocommerce_enqueue_styles&#039;, &#039;comain_disable_wc_styles&#039;);
function comain_disable_wc_styles($styles) {
    if (!is_checkout() &amp;&amp; !is_cart() &amp;&amp; !is_account_page()) {
        unset($styles[&#039;wc-blocks-style&#039;]);
    }
    return $styles;
}

// 7. Add missing security headers via PHP
add_action(&#039;send_headers&#039;, function() {
    header(&#039;X-Frame-Options: SAMEORIGIN&#039;);
    header(&#039;X-Content-Type-Options: nosniff&#039;);
    header(&#039;Referrer-Policy: strict-origin-when-cross-origin&#039;);
    header(&#039;Permissions-Policy: geolocation=(), microphone=(), camera=()&#039;);
    header(&#039;X-XSS-Protection: 1; mode=block&#039;);
});

// 8. Remove query strings from WP Rocket cache buster
add_filter(&#039;rocket_cache_busting_filename&#039;, function($filename) {
    return preg_replace(&#039;/-[a-f0-9]{32,}/&#039;, &#039;&#039;, $filename);
});

if (!defined(&#039;REST_REQUEST&#039;) || !REST_REQUEST) {
    echo &#039;&lt;!-- comain-speed-optimizer active --&gt;&#039;;
}
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//kmceramic.company/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://kmceramic.company/post-sitemap.xml</loc>
		<lastmod>2026-07-13T13:26:47+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://kmceramic.company/page-sitemap.xml</loc>
		<lastmod>2026-07-11T13:34:52+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://kmceramic.company/product-sitemap.xml</loc>
		<lastmod>2026-06-30T01:00:16+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://kmceramic.company/astra-advanced-hook-sitemap.xml</loc>
		<lastmod>2026-07-04T01:02:58+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://kmceramic.company/local-sitemap.xml</loc>
		<lastmod>2026-05-04T08:17:24+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->