Support » Plugin: Hummingbird – Optimize Speed, Enable Cache, Minify CSS & Defer Critical JS » Relative path for compressed / combined assets

  • Resolved coholm

    (@coholm)


    First of all: Thank you for the great plugin!

    I’m using my wordpress setup in a quite unusual setup. I have mapped two domains to the same wordpress installation, but I’m not using the native Multi Domain Network function of wordpress, because I don’t need different settings, themes, etc for the two domains.

    The problem is, that some plugins including Hummingbird don’t work that way.
    The problem is, that they put absolute path in the source.
    When a page i cached or an asset is compressed or combined, it causes absolute paths to show up to the assets of the different domains.

    Example:
    domainA.com/wp-content/plugins/humm/assets/js/frontend.js
    shows up in the source of
    domainB.com

    Ususally this is not a big problem. However in my situation it is, because domainA.com is blocked in the company network setup that I work for.
    That means domainA.com can’t be loaded within the network of the company. That means when I try to load domainB.com, scripts that are called within it source can’t be loaded.

    To avoid that problem, I have setup everything to have relative paths and I’m using the plugin “Make Paths Relative” to make it a bit easier.

    I there a way I can call combined / compressed assets with a relative path?:
    <script type=’text/javascript’ src=’/wp-content/plugins/dk-pdf/assets/js/frontend.js’></script>

    instead of
    <script type=’text/javascript’ src=’https://domainA.org/wp-content/plugins/dk-pdf/assets/js/frontend.js’></script&gt;

    I have bought WP-Rocket and the new WP-Optimize Caching plugins and they both work great in normal setups, but caused all kinds of problems in a setup where you need to use multiple domains for one wordpress installation.
    Hummingbird did not cause these problems and most functions (caching) can be used without a problem. Only problem that occurs is when I’m using asset management.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Kasia – WPMU DEV Support

    (@wpmudev-support2)

    Hello @coholm ,

    Let me check that with Hummingbird developer if that would be possible, or there is a hook for that.

    kind regards,
    Kasia

    Plugin Support Kasia – WPMU DEV Support

    (@wpmudev-support2)

    Hello @coholm ,

    We have some additional question: is your WordPress install a single WP that have two domains?

    Thread Starter coholm

    (@coholm)

    Hi,
    Yes it’s a single WP that has two domains

    Hi @coholm,

    You could try using the set_url_scheme filter to manually replace paths or “cut off” the domain part: https://developer.wordpress.org/reference/hooks/set_url_scheme/

    Best regards,
    Anton

    Thread Starter coholm

    (@coholm)

    Could you explain to me how to use set_url_scheme ?
    I can not find any further explanations to this filter on google

    You’d have to add something like this to your functions.php file and adjust to your needs:

    add_filter( 'set_url_scheme', 'adjust_url_string' );
    function adjust_url_string( $url ) {
    	// remove the domain from $url and return the string
    }

    Best regards,
    Anton

    Thread Starter coholm

    (@coholm)

    Thanks for getting back to me on this.

    adjust to your needs:

    Will this code already work or do I have to hadd anything to it.
    Could you provide a sample code with a sample domain.

    I just want the domain name stripped off of the path and have relative paths

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @coholm

    Can you try out the following snippet in the functions.php file of your child-theme or in a MU plugin?

    <?php
    add_filter( 'set_url_scheme', 'adjust_url_string' );
    function adjust_url_string( $url ) {
    	if ( is_admin() ) {
    		return $url;
    	}
    	$extensions_to_relativate = array( '.js', '.css' );
    	foreach ( $extensions_to_relativate as $extension ) {
    		if ( substr( $url, - strlen( $extension ) ) === $extension ) {
    			$parsed_url = parse_url( $url );
    			$new_url = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
    			$new_url .= isset( $parsed_url['query'] ) ? $parsed_url['query'] : '';
    			$url = $new_url;
    		}
    	}
    	  return $url;
    }

    Thank you,
    Dimitris

    Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hello @coholm

    I hope you are doing well!

    We haven’t heard back from you for a while now so we’ve marked this ticket as resolved. If you do have any followup questions or require further assistance feel free to reopen it and let us know here.

    Kind regards,
    Nastia

    Thread Starter coholm

    (@coholm)

    Has something in the core changed for the above code to not work anymore?
    Some script urls are still relative, but some are absolute now.

    I have recently updated to wp 5.5

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @coholm

    Sorry delay here and to hear that the code isn’t working anymore.

    I pinged our developers to review this code for you.

    Once we receive an update from them, we will let you know.

    Best Regards
    Patrick Freitas

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @coholm

    Our developers checked the code and it seems to still working fine.

    Could you double-check if the codes that are wrong are loading from Assets Optimization?

    The plugin will only render the code if this is called using the correct wp_enqueue_script and wp_enqueue_style

    Best Regards
    Patrick Freitas

    Thread Starter coholm

    (@coholm)

    Thanks for your help. A different plugin was causing the problem.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Relative path for compressed / combined assets’ is closed to new replies.