• Resolved DaanvandenBergh

    (@daanvandenbergh)


    Hi!

    I’ve found a workaround, so this isn’t high priority, but I still wanted to inform you.

    When using the sgo_javascript_combine_exclude filter, to exclude an enqueued JS library by handle, when the src is a protocol relative URL your plugin doesn’t handle this properly.

    An example, if you enqueue a script with source: //yourdomain.com/wp-content/uploads/script.js and add this to the list of exclusions using the aforementioned filter, this’ll result in yourdomain.com/wp-content/uploads/script.js being added to the list of exclusions (the $this->excluded_urls property).

    It’s due to this line of code in the Js_Combinator class:

    Cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Delyan Delov

    (@delyandelov)

    Hello @daanvandenbergh,

    I have performed an extensive check of the issue you have described and have not managed to recreate it on my end. I have created a simple JS file and enqueued it in my test WordPress theme. After that, I excluded the script using its handle via our filter and the JS script was successfully excluded. Then I replaced the handle with the actual script source (https://www.mydomain.com/WP/wp-content/uploads/script.js) and the script was not excluded at all.

    Could you please provide a bit more information about your exact actions and what is the incorrect behavior you are observing?

    Thread Starter DaanvandenBergh

    (@daanvandenbergh)

    Did you enqueue it using a protocol relative URL?

    Plugin Support Delyan Delov

    (@delyandelov)

    I enqueued the script like this:

    wp_register_script( 'my-script', 'https://www.mydomain.com/wp-content/uploads/script.js', array('jquery'), '1.0', true );
    wp_enqueue_script( 'my-script' );

    Please let us know if you are using different approach so we can recreate the issue on our end.

    Thread Starter DaanvandenBergh

    (@daanvandenbergh)

    yes, now make that URL protocol relative, i.e. //www.mydomain.com/etc.

    Plugin Support Delyan Delov

    (@delyandelov)

    I have excluded the JS script as requested. Here is the full code of the filter I have added to the theme’s functions.php file:

    add_filter( 'sgo_javascript_combine_exclude', 'js_combine_exclude' );
    function js_combine_exclude( $exclude_list ) {
    $exclude_list[] = '//www.mydomain.com/wp-content/uploads/script.js';
    return $exclude_list;
    }

    and the script was NOT excluded from the Combine JS Files functionality, which is the expected behavior. I managed to exclude the script by only adding its handle to the $exclude_list.

    Please check again the scenario on your end and let us know if there is some misunderstanding.

    Thread Starter DaanvandenBergh

    (@daanvandenbergh)

    So, just to be clear, this works in your case? Because it doesn’t in mine:

    Enqueue a script using a protocol-relative URL:

    wp_register_script( 'my-script', '//www.mydomain.com/wp-content/uploads/script.js', array('jquery'), '1.0', true );
    wp_enqueue_script( 'my-script' );

    And then try to exclude it using it’s handle:

    add_filter( 'sgo_javascript_combine_exclude', 'js_combine_exclude' );
    function js_combine_exclude( $exclude_list ) {
    $exclude_list[] = 'my-script';
    return $exclude_list;
    }

    This, in my case, results in the file still being combined with other JS files.

    Plugin Support Dimitar Petrov

    (@demiro)

    Hello @daanvandenbergh,

    Thank you for the feedback, we highly appreciate it!

    The URL defined as a source of the script should be either full URL or relative path, relative to the current location of the invoking script. Our code does not support protocol-relative sources as you noticed after checking the Js_Combinator class.

    We follow the best practises outlined by the official WordPress documentation and just in case, we have double-checked the documentation in order to assure that the Full URL is recommended there. You can also check the document here.

    Best Regards,
    Dimitar Petrov

    Thread Starter DaanvandenBergh

    (@daanvandenbergh)

    Ah! Thanks for pointing that out to me. I didn’t know that. So, it wasn’t a bug after all.

    Resolved. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Protocol-relative URLs can’t be excluded using a filter’ is closed to new replies.