• Resolved robertrosanke

    (@robertrosanke)


    Hello,

    I’m currently reviewing our website and have noticed that easily 40% of the CSS file size (gzipped) is unnecessary. Of course, there’s still room for optimization within the files themselves, but simply removing unnecessary files would save nearly 40%, so I’m now opening support tickets with the respective plugin developers.

    This ticket concerns the following file:

    • /wp-content/plugins/woocommerce-paypal-payments/assets/ppcp-local-alternative-payment-methods-css-gateway.css

    The file contains only one rule and is loaded on our homepage. I suspect that the file is simply always loaded, even when it isn’t needed.

    .payment_methods li[class*=payment_method_ppcp-] label img{max-height:24px}
    • It would probably be better to load the file only in the checkout + pay for order page.
    • Alternative: replace it with inline styles directly in the img-tag.

    I would appreciate it if this small improvement could be implemented.
    Thank you very much.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Krystian Syde

    (@inpsydekrystian)

    Hello @robertrosanke

    The plugin already restricts this stylesheet to the cart, checkout, and order-payment pages. The relevant code in LocalAlternativePaymentMethodsModule.php contains the following guard:

    add_action(
        'wp_enqueue_scripts',
        function () use ( $c ) {
            if ( ! is_checkout() && ! is_cart() && ! is_wc_endpoint_url( 'order-pay' ) ) {
                return;
            }
    
            // ...
    
            wp_enqueue_style(
                'ppcp-local-apms-gateway',
                $asset_getter->get_asset_url( 'gateway.css' ),
                // ...
            );
        }
    );
    

    Therefore, under normal circumstances, this file should not be loaded on the homepage.

    Its presence there is likely specific to your setup, for example, a caching or CSS-optimization serving an aggregated stylesheet, a cached page containing the reference, or another component causing WC to identify the homepage as a checkout-related page. Please temporarily disable CSS aggregation and optimization, purge all site and CDN caches, and check the homepage source again.

    Your observation regarding the cart page is valid: the stylesheet is currently also loaded there, although the .payment_methods list is generally not present. We can consider restricting that further as a minor optimization.

    Kind Regards
    Krystian

    Thread Starter robertrosanke

    (@robertrosanke)

    Hallo @inpsydekrystian ,

    Thanks for the quick response.

    This ticket is regarding the style handle “pppc-pwc-payment-method-css”.

    It seems like it is located unter “/modules/ppcp-local-alternative-payment-methods/src/PWCPaymentMethod.php“, class PWCPaymentMethod .

    	public function get_payment_method_script_handles(): array {
    wp_register_script(
    'ppcp-pwc-payment-method',
    $this->asset_getter->get_asset_url( 'pwc-payment-method.js' ),
    array(),
    $this->version,
    true
    );

    wp_enqueue_style(
    'ppcp-pwc-payment-method',
    $this->asset_getter->get_asset_url( 'gateway.css' ),
    array(),
    $this->version
    );

    return array( 'ppcp-pwc-payment-method' );
    }

    It is always included, and there is no prior check to see if it is actually necessary in the current context.

    Plugin Support Krystian Syde

    (@inpsydekrystian)

    Hello @robertrosanke

    This issue has already been fixed in the development version through the following change: PR #4465 – Remove unconditional CSS enqueue from PWCPaymentMethod

    The unconditional wp_enqueue_style() call has been removed from PWCPaymentMethod::get_payment_method_script_handles(). The method now only registers and returns the JavaScript handle.

    The CSS is instead enqueued through LocalAlternativePaymentMethodsModule.php, where it is restricted to the relevant pages:

    if ( ! is_checkout() && ! is_cart() && ! is_wc_endpoint_url( 'order-pay' ) ) {
    return;
    }

    Therefore, the stylesheet should only load on the checkout, cart, and order-payment pages once this change is included in the released plugin version. Let me know if things work differently on your end; I’ve already confirmed this with the devs to be sure.

    Kind Regards
    Krystian

    Thread Starter robertrosanke

    (@robertrosanke)

    Hello @inpsydekrystian ,

    Thanks for the info. In that case, that issue is resolved, and we’re looking forward to the new plugin version.

    Have a great start to the week!

    Plugin Support Krystian Syde

    (@inpsydekrystian)

    Hello @robertrosanke

    No worries, wishing you a great week aswell!

    If this helped and you’re happy with the support, feel free to leave a quick review on WordPress. It means a lot to us and shows that we are needed as support.

    Kind regards,
    Krystian

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.