• Resolved NaFi

    (@nafi121)


    Hi

    im using below code to enqueue google AdSense only for US, I have an issue on caching, If a US visitor visits the page this enqueue get cached and show to non US visitors as well. Is there a way to prevent this from happening ?

    if ($countryIsoCode !== null && $countryIsoCode == "US") {
            wp_enqueue_script(
                'adsbygoogle', // Script handle
                'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-{pub_id}', // Script URL
                array(), // Dependencies (none in this case)
                null, // Version (null to prevent caching)
                false // Load in the footer (true) or header (false)
            );
        }
Viewing 3 replies - 1 through 3 (of 3 total)
  • So that you can display different content or execute different code depending on the location/IP address, you need a so-called Cache Vary. You also need a GeoIP database, which you have to configure accordingly in the configuration of the LiteSpeed web server. With both functions you get what you need. However, the GeoIP function of the LiteSpeed web server must be activated on your hosting, which is usually not the case with many shared hostings. The GeoIP function is a web server function and cannot be activated by the cache plugin.

    You can find further information about GeoIP in the LiteSpeed web server documentation:

    https://docs.litespeedtech.com/lsws/cp/cpanel/geoip/

    Thread Starter NaFi

    (@nafi121)

    cool , will test that out so the solution is to server cache data based on user geo location ?

    Yes. When using the GeoIP function, you must note that you can no longer warm up the cache, or the cache can only be warmed up for the IP range of your server’s location.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_enqueue_script based on country’ is closed to new replies.