• Resolved gbruzzo

    (@gbruzzo)


    Hello there,

    hope you are all well.

    we encountered an issue/conflict between SG Optimizer and YITH Amazon S3 Storage for Woocommerce.

    Amazon S3 Storage enables storage of Woocommerce DL files on Amazon S3.

    Problem occurs as follows:
    – SG Optimizers combine JS is enabled
    – customer not logged into site
    – customer has bought as guest (they do not have an account).
    – customer inserts order number and billing email in standard Woocommerce Order tracking page. When clicking on the Download button, the file does not download (Pressing the DL button usually results in a fast redirection from the order tracking page to an html page with the Amazon link back to the tracking page – during which time the download starts.
    In this case there is no redirection back and the download does not start.

    – we tried testing with TwentyTwentyone or Storefront + WC + SG Optimizer
    – we tried identifying the ‘culprit js’ by process of elimination from the combined js file as follows (for twentytwentyone theme)

    add_filter( 'sgo_javascript_combine_exclude', 'js_combine_exclude' );
    function js_combine_exclude( $exclude_list ) {
        $exclude_list[] = 'jquery-blockui';
        $exclude_list[] = 'jquery-migrate';
        $exclude_list[] = 'js-cookie';
        $exclude_list[] = 'wc-add-to-cart-variation';
        $exclude_list[] = 'wc-add-to-cart';
        $exclude_list[] = 'wc-cart-fragments';
        $exclude_list[] = 'woocommerce';
        $exclude_list[] = 'woocommerce-no';
        $exclude_list[] = 'wp-embed';
        $exclude_list[] = 'twenty-twenty-one-responsive-embeds-script';
        $exclude_list[] = 'twenty-twenty-one-primary-navigation-script';
        $exclude_list[] = 'twenty-twenty-one-ie11-polyfills';
        $exclude_list[] = 'twenty-twenty-one-ie11-polyfills-asset';
        return $exclude_list;
    }

    the javascript that remains in the combined files are three pieces of inline js we cannot eliminate, specifically:

    document.body.classList.remove("no-js");;
    if ( -1 !== navigator.userAgent.indexOf( 'MSIE' ) || -1 !== navigator.appVersion.indexOf( 'Trident/' ) ) {
    		document.body.classList.add( 'is-IE' );
    	};
    (function () {
    			var c = document.body.className;
    			c = c.replace(/woocommerce-no-js/, 'woocommerce-js');
    			document.body.className = c;
    		})();;
    /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",(function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())}),!1);

    Still the issue remains – the downloads become possible only when JS combination is disabled.

    – The issue does not occur when the Download is ‘internal / tied to a file that resides on the server’;

    – Downloads are set to ‘Force’;

    – Also: following the link from the order confirmation email (the same link as on the Order tracking page) results in the file actually being downloaded.

    Does this suggest anything to you? I will reach out to the YITH developers, but if it would be helpful to get extra thoughts before I do. Something in the redirection process gets stopped, and I cannot figure what (nor can I get to it by process of elimination).

    Thanks for any thoughts you may have about this

    Giacomo Bruzzo

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Stoyan Georgiev

    (@stoyangeorgiev)

    Hey there @gbruzzo

    If the plugin is adding the scripts as an inline content, you can exclude inline script from being combined using the filter we’ve designed for that purpose. Here’s an example of the code:

    add_filter( 'sgo_javascript_combine_excluded_inline_content', 'js_combine_exclude_inline_script' );
    function js_combine_exclude_inline_script( $exclude_list ) {
        $exclude_list[] = 'first few symbols of inline content script';
    
        return $exclude_list;
    }

    But make sure you insert something specifically for that inline script, since adding that filter with let’s say ‘document’ will result in skipping the combination for all other scripts containing ‘document.

    If you have any issues feel free to reach back to us.

    Kind regards,
    Stoyan

    Thread Starter gbruzzo

    (@gbruzzo)

    Dear @stoyangeorgiev

    thank you for pointing it out to me. I figured out that the ‘culprit’ was

    
    (function () {
    var c = document.body.className;
    c = c.replace(/woocommerce-no-js/, 'woocommerce-js');
    document.body.className = c;
    })();
    

    This turns out to be a function in woocommerce/includes/wc-template-functions.php
    https://woocommerce.wp-a2z.org/oik_api/wc_no_js/

    once this inline script is removed from the combined js, downloads resume correctly.

    Will flag the issue to YITH developers.

    Thanks again for pointing me in the right direction.

    Giacomo Bruzzo

    • This reply was modified 3 years, 7 months ago by gbruzzo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conflict with YITH Amazon S3 Storage for Woocommerce’ is closed to new replies.