justinhelmer
7/11/2017 - 5:29 PM

example of _thirdPartyScripts using async callback

example of _thirdPartyScripts using async callback

define([
  'config',
  'scriptjs'
], function (config, $script) {
  'use strict';

  return {
    load: (cb) => {
      let scripts = [
        '/mew20/scripts/util/popStateFix.js',
        '/mew20/scripts/util/itunesLoader.js', 
        '/mew20/scripts/util/gatewayLoader.js'
      ];
      
      if (App.config.BrightTag.siteId) {
        scripts.push('//s.btstatic.com/tag.js#site=' + App.config.BrightTag.siteId);
      }

      var tealiumKS = ENV_CONFIG.tealium_enabled === 'on' ? true : false;

      if (tealiumKS) {
        var tealiumEnvironment = ENV_CONFIG.tealium_environment,
          brand = App.config.brand,
          brandNameForTealium = brand === 'mcom' ? 'macys' : brand;

        scripts.push('//tags.tiqcdn.com/utag/' + brandNameForTealium + '/main/' + tealiumEnvironment + '/utag.js');
      }
      
      $script(scripts, 'bundle');
      $script.ready('bundle', cb);
    }
  };
});

// usage
require('_thirdPartyScripts.async.js').load(() => {
  console.log('ready!');
});