Commit 7a2ef151 authored by Mike Carper's avatar Mike Carper
Browse files

Issue #2904702 by mikeytown2, oppure: Need help with deferring javascript

parent a28725b7
Loading
Loading
Loading
Loading
+49 −56
Changes for advagg_mod/advagg_mod.module: 49 added lines, 56 removed lines.
Original line number Diff line number Diff line
@@ -1235,10 +1235,21 @@ function advagg_mod_get_lists(array $js = array(), array $css = array()) {
      // Html5shiv and html5shiv-printshiv.
      '/html5shiv.',
      '/html5shiv-printshiv.',
      // Google Admanager Needs to be in the header.
      '/google_service.',
    );

    // Do not move to footer inline list.
    $header_inline_list = array();
    $header_inline_list = array(
      // Google Analytics should be in the header to verify for Webmaster tools.
      'GoogleAnalyticsObject',
      'window.google_analytics_uacct',
      // Google Admanager Needs to be in the header.
      'GS_googleAddAdSenseService(',
      'GS_googleEnableAllServices(',
      'GA_googleAddSlot(',
      'GA_googleFetchAds(',
    );

    // Do not defer/async list.
    $no_async_defer_list = array(
@@ -1247,7 +1258,21 @@ function advagg_mod_get_lists(array $js = array(), array $css = array()) {
      // Maps.
      '//dev.virtualearth.net',
      '//api.maps.yahoo.com',
      // Google Admanager can't be forced defer/async.
      '/google_service.',
    );
    // Openlayers.
    if (module_exists('openlayers')) {
      // Openlayers fix; external scripts can not be loaded out of order.
      // Cloudmade.
      $path = variable_get('openlayers_layers_cloudmade_js', '');
      if (valid_url($path, TRUE)) {
        $no_async_defer_list['openlayers_layers_cloudmade'] = $path;
      }
      // Google.
      $mapdomain = variable_get('openlayers_layers_google_mapdomain', 'maps.google.com');
      $no_async_defer_list['openlayers_layers_google'] = $mapdomain . '/maps';
    }

    // Wrap inline js so it does not run until the condition is TRUE.
    // Inline search string => js condition.
@@ -1259,13 +1284,21 @@ function advagg_mod_get_lists(array $js = array(), array $css = array()) {
    $inline_js_wrap_skip_list[] = '._fbq';
    $inline_js_wrap_skip_list[] = '.fbq';
    $inline_js_wrap_skip_list[] = 'gtm.start';
    if (module_exists('devel')) {
      $inline_js_wrap_skip_list[] = 'function krumo(';
    }
    if (module_exists('googleanalytics')) {
    $inline_js_wrap_skip_list[] = '_gaq.push(["_';
      $inline_js_wrap_skip_list[] = '"GoogleAnalyticsObject"';
      $header_inline_list[] = 'GoogleAnalyticsObject';
    $inline_js_wrap_skip_list[] = 'ga("';
    $inline_js_wrap_skip_list[] = "ga('";
    $inline_js_wrap_skip_list[] = 'GoogleAnalyticsObject';
    $inline_js_wrap_skip_list[] = 'window.google_analytics_uacct';
    $inline_js_wrap_skip_list[] = 'function krumo(';
    // Google Admanager can not be wrapped in a callback function.
    $inline_js_wrap_skip_list[] = 'GS_googleAddAdSenseService(';
    $inline_js_wrap_skip_list[] = 'GS_googleEnableAllServices(';
    $inline_js_wrap_skip_list[] = 'GA_googleAddSlot(';
    $inline_js_wrap_skip_list[] = 'GA_googleFetchAds(';
    $inline_js_wrap_skip_list[] = 'GA_googleFillSlot(';
    $inline_js_wrap_skip_list[] = 'adsbygoogle';
    if (module_exists('h5p')) {
      $inline_js_wrap_skip_list[] = 'H5PIntegration';
    }

    // Get inline defer js skip list string and convert it to an array.
@@ -1274,10 +1307,16 @@ function advagg_mod_get_lists(array $js = array(), array $css = array()) {
    $inline_js_defer_skip_list[] = '._fbq';
    $inline_js_defer_skip_list[] = '.fbq';
    $inline_js_defer_skip_list[] = 'gtm.start';
    if (module_exists('googleanalytics')) {
    $inline_js_defer_skip_list[] = '_gaq.push(["_';
      $inline_js_defer_skip_list[] = '"GoogleAnalyticsObject"';
    }
    $inline_js_defer_skip_list[] = 'GoogleAnalyticsObject';
    $inline_js_defer_skip_list[] = 'window.google_analytics_uacct';
    // Google Admanager can not be wrapped in a callback function.
    $inline_js_defer_skip_list[] = 'GS_googleAddAdSenseService(';
    $inline_js_defer_skip_list[] = 'GS_googleEnableAllServices(';
    $inline_js_defer_skip_list[] = 'GA_googleAddSlot(';
    $inline_js_defer_skip_list[] = 'GA_googleFetchAds(';
    $inline_js_defer_skip_list[] = 'GA_googleFillSlot(';
    $inline_js_defer_skip_list[] = 'adsbygoogle';

    // If there is a fast clicker, ajax links might not work if ajax.js is
    // loaded in the footer.
@@ -1292,52 +1331,6 @@ function advagg_mod_get_lists(array $js = array(), array $css = array()) {
      ),
    );

    // Openlayers.
    if (module_exists('openlayers')) {
      // Openlayers fix; external scripts can not be loaded out of order.
      // Cloudmade.
      $path = variable_get('openlayers_layers_cloudmade_js', '');
      if (valid_url($path, TRUE)) {
        $no_async_defer_list['openlayers_layers_cloudmade'] = $path;
      }
      // Google.
      $mapdomain = variable_get('openlayers_layers_google_mapdomain', 'maps.google.com');
      $no_async_defer_list['openlayers_layers_google'] = $mapdomain . '/maps';
    }

    // Google Admanager.
    if (module_exists('google_admanager')) {
      // Needs to be in the header.
      $header_file_list[] = '/google_service.';

      // Needs to be in the header.
      $header_inline_list[] = 'GS_googleAddAdSenseService(';
      $header_inline_list[] = 'GS_googleEnableAllServices(';
      $header_inline_list[] = 'GA_googleAddSlot(';
      $header_inline_list[] = 'GA_googleFetchAds(';

      // Can not be async/defered.
      $no_async_defer_list[] = '/google_service.';

      // Can not be wrapped in a callback function.
      $inline_js_wrap_skip_list[] = 'GS_googleAddAdSenseService(';
      $inline_js_wrap_skip_list[] = 'GS_googleEnableAllServices(';
      $inline_js_wrap_skip_list[] = 'GA_googleAddSlot(';
      $inline_js_wrap_skip_list[] = 'GA_googleFetchAds(';
      $inline_js_wrap_skip_list[] = 'GA_googleFillSlot(';

      // Can not be wrapped in a callback function.
      $inline_js_defer_skip_list[] = 'GS_googleAddAdSenseService(';
      $inline_js_defer_skip_list[] = 'GS_googleEnableAllServices(';
      $inline_js_defer_skip_list[] = 'GA_googleAddSlot(';
      $inline_js_defer_skip_list[] = 'GA_googleFetchAds(';
      $inline_js_defer_skip_list[] = 'GA_googleFillSlot(';
    }

    if (module_exists('h5p')) {
      $inline_js_wrap_skip_list[] = 'H5PIntegration';
    }

    $move_js_to_footer = variable_get('advagg_mod_js_footer', ADVAGG_MOD_JS_FOOTER);
    $defer_setting = variable_get('advagg_mod_js_defer', ADVAGG_MOD_JS_DEFER);
    $async_setting = variable_get('advagg_mod_js_async', ADVAGG_MOD_JS_ASYNC);