• Resolved jetxpert

    (@jetxpert)


    After a decent amount of research and testing, I would like to share a method that will allow you to block unwanted outgoing HTTP requests for either single or multiple URLs.

    As most of you know, outgoing HTTP requests are implemented by WordPress, Themes, and Plugins to perform many functions. Most of them relate to checking your website to determine if any updates are needed. Others, simply check your website for license validation or to simply perform miscellaneous theme or plugin tests which, quite frankly, can slow down your website.

    To help minimize these effects (i.e., slowing down your website), follow the method provided below.

    Method:

    (1) Install and activate Snitch.

    (2) Using Snitch, determine which URL(s) are making outgoing HTTP requests and potentially slowing down your website.

    (3) Add the snippet provided below to your functions.php file – or – install and activate the plugin “Code Snippets.” I personally recommend this plugin over adding the code to your functions.php file.

    Code:

    add_filter( 'pre_http_request',
        function ( $bFalse, $aReqParams, $sUrl ) {
            if ( strpos( $sUrl, '//DOMAINURL1/PATH1') ) {
                $bFalse = null;
            }
            return $bFalse;
    		
    		if ( strpos( $sUrl, '//DOMAINURL2/PATH2') ) {
                $bFalse = null;
            }
            return $bFalse;
        },
        PHP_INT_MAX,
        3
    );

    Where DOMAINURL1/PATH1, DOMAINURL2/PATH2 are the URLs/paths obtained from Snitch. If you need to add more URLs, simply repeat the code that starts with “if …” and ends with “… return $bFalse;”

    If you know how to simplify the above code, please let us know!

    I implemented the above and our website loading time decreased by .2 – .9 seconds.

    Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter jetxpert

    (@jetxpert)

    Method: (continued)

    (4) Deactivate and delete Snitch.

    Cheers!

    Question @jetxpert. Does Snitch’s built in blocking functionality not do this? As in blocking a url via the built in Block functionality in Snitch does not result in performance improvements, but your blocking method does? Does this mean the blocks i put in place via Snitch’s built in functionality are essentially meaningless for my sites performance, and thus need to be recreated via your method?

    • This reply was modified 4 years, 8 months ago by jazir5.
    • This reply was modified 4 years, 8 months ago by jazir5.
    Thread Starter jetxpert

    (@jetxpert)

    @jazir5,

    Yes, Snitch can block either single or multiple URLs. However, from our study, Snitch slows down our website more than the method provided above.

    Don’t get me wrong, Snitch is a great plugin. Use whichever method suits you best.

    Cheers!

    @jetxpert

    Yeah i’m noticing snitch causes a big performance hit now that you mention it, i will be switching to your method. Using snitch to identify the URLs needed to block then adding it to functions.php as described above. I greatly appreciate the script you posted, thank you!

    @jetxpert

    Will your function work with wildcards(*)? For instance blocking any url that contains a portion of the string inserted, i.e, https://jetelements.zemez.io/updates/*

    Thread Starter jetxpert

    (@jetxpert)

    @jazir5,

    I don’t know. Best way to find out is to perform your own test(s).

    Above code obtained here.

    Cheers!

    Thread Starter jetxpert

    (@jetxpert)

    Update:

    No input received for quite some time. Issue, therefore, considered resolved.

    Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Snippet to Block Outgoing HTTP Requests (Single or Multiple URLs)’ is closed to new replies.