Delay Loading Intercom

Delay Loading Intercom

Can I delay loading Intercom on my site to reduce the JS load? i.e. only load it after a page is fully loaded for a visitor?

You can modify the Intercom load function by splitting it out like this, and it runs inside a setTimeout function.

// Intercom
      window.intercomSettings = {
        app_id: "<YOUR WIDGET ID>"
      };
 
     var w = window;
    var ic = w.Intercom;
    if (typeof ic === "function") {
        ic('reattach_activator');
        ic('update', w.intercomSettings);
    } else {
        var d = document;
        var i = function() {
            i.c(arguments);
        };
        i.q = [];
        i.c = function(args) {
            i.q.push(args);
        };
        w.Intercom = i;
        var l = function() {
            var s = d.createElement('script');
            s.type = 'text/javascript';
            s.async = true;
            s.src = 'https://widget.intercom.io/widget/<YOUR WIDGET ID>';
            var x = d.getElementsByTagName('script')[0];
            x.parentNode.insertBefore(s, x);
        };
        l();
    }

The difference is that the part that runs l() normally is onLoad and that gets stuffed up after the setTimeout.

You can also strip out the l() function entirely if you like (and just have the variables declared etc) and just run it, as it’ll be wrapped in a setTimeout function.