javascript - GeoIP redirect - loading after DOM ready -
the javascript below redirects based on geoip :
<script type="text/javascript"> var script = document.createelement('script'); script.src = "//freegeoip.net/json/?callback=nygeoip"; document.getelementsbytagname('head')[0].appendchild(script); function nygeoip(d) { if (d.country_code === 'xx') { window.location = 'http://www.domain.com'; } } </script>
can please let me know how amend code calls freegeoip server after dom ready (after page load).
the freegeoip server not respond blocks page rendering , , tools such gtmetrix/webpagetest show loading times of 1-2 minutes when freegeoip server not responding.
include jquery library , use document ready function:
<script type="text/javascript"> $(document).ready(function(){ var script = document.createelement('script'); script.src = "//freegeoip.net/json/?callback=nygeoip"; document.getelementsbytagname('head')[0].appendchild(script); function nygeoip(d) { if (d.country_code === 'xx') { window.location = 'http://www.domain.com'; } } }) </script>
Comments
Post a Comment