Support » Plugin: Autoptimize » Protocol-less URL support

  • Resolved RossWPDev

    (@rosswpdev)


    Hello

    On my site I have Autoptimize (latest version 1.8.1) (which is brilliant by the way) installed along with WooCommerce (2.1.5) and I have noticed that starting with WooCommerce version 2.1 they now use protocol-less URL’s e.g.

    //example.com/wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js?ver=2.1.5

    Is there anyway I can get Autoptimize to pick these up? If I modify the core WooCommerce code that add’s these resources by adding a protocol they are then picked up by Autoptimize, but obviously I don’t want to modify core files!

    Any help would be greatly appreciated.

    Many Thanks,
    Ross

    https://wordpress.org/plugins/autoptimize/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Frank Goossens

    (@futtta)

    I’ll look into that, a solution for that might just still make it into 1.8.2. Now that I come to think of it; maybe I should switch to protocol-less URL’s. What do you think?

    RossWPDev

    (@rosswpdev)

    Great, thanks, would be good to see this in 1.8.2 🙂

    I believe that the advantage of using the protocol-less urls are that it allows them to inherit the pages current protocol (http / https) preventing the need for any logic in the code to work out the current pages protocol. Which all sounds good..

    Found this article which goes over the topic in more detail http://www.paulirish.com/2010/the-protocol-relative-url

    Thanks,
    Ross

    Plugin Author Frank Goossens

    (@futtta)

    Hi Ross;
    Not going to change output for now, but regarding aggregating protocol-less JS/CSS-links, could you try this?

    1. Open up /wp-content/plugins/autoptimize/classes/autoptimizeBase.php
    2. On line 26 change:

    //Converts an URL to a full path
    	protected function getpath($url) {
    		if ((strpos($url,'//')===false) && 	(strpos($url,parse_url(AUTOPTIMIZE_WP_SITE_URL,PHP_URL_HOST))===false))		{
    			$url = AUTOPTIMIZE_WP_SITE_URL.$url;
    		}
            $path = str_replace(AUTOPTIMIZE_WP_ROOT_URL,'',$url);
    	    if(preg_match('#^((https?|ftp):)?//#i',$path)) {
                /** External script/css (adsense, etc) */
           		return false;
           	}
            $path = str_replace('//','/',WP_ROOT_DIR.$path);
            return $path;
    	}

    into:

    //Converts an URL to a full path
    	protected function getpath($url) {
    		if (strpos($url,'//')===0) {
    			$url = "http:".$url;
    		} else if ((strpos($url,'//')===false) && (strpos($url,parse_url(AUTOPTIMIZE_WP_SITE_URL,PHP_URL_HOST))===false)) {
    			$url = AUTOPTIMIZE_WP_SITE_URL.$url;
    		}
            $path = str_replace(AUTOPTIMIZE_WP_ROOT_URL,'',$url);
    	    if(preg_match('#^((https?|ftp):)?//#i',$path)) {
                /** External script/css (adsense, etc) */
           		return false;
           	}
            $path = str_replace('//','/',WP_ROOT_DIR.$path);
            return $path;
    	}

    3. save file
    4. empty Autoptimize Cache (and whatever page caching plugin you use).

    Based on (limited) local tests this should do the trick. If this indeed does work, it’ll be included in 1.8.2.

    frank

    RossWPDev

    (@rosswpdev)

    Hey futtta

    Thanks for the reply. I’ve added in the updated function and it looks like it’s working great!

    Thanks,
    Ross

    Plugin Author Frank Goossens

    (@futtta)

    great, thanks for the feedback. enjoy your weekend!

    frank

    Plugin Author Frank Goossens

    (@futtta)

    by the way, get regular questions about how to configure autoptimize for woocommerce, would you mind sharing your configuration?

    RossWPDev

    (@rosswpdev)

    Hey

    Sure, although I have not needed to do much in order to get Autoptimize working with WooCommerce….

    My current setup is a standard WooCommerce install (2.1.5) with latest WordPress (3.8.1).

    My Autoptimize settings are:

    • Optimize HTML Code?: true
    • Optimize JavaScript Code?: true (exclude jQuery.js)
    • Optimize CSS Code?: true
    • Save aggregated script/css as static files?: true

    (all other fields are unchecked)

    If anyone has any specific questions relating to a working WooCommerce + Autoptimize setup feel free to ask.

    Thanks,
    Ross

    Plugin Author Frank Goossens

    (@futtta)

    Thanks for the feedback Ross!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Protocol-less URL support’ is closed to new replies.