0

I try to load JavaScript with drupal_add_js(), but it's not easy, and after fixing the loading of external JavaScript, I faced off a loading order issue: My external JavaScript is loaded after my local ones, and I would like the opposite behavior. Is it possible with Drupal 6?

Additional problem but optional: Is it possible to load these in footer instead of the header?

This is my code.

function d6_ce_susy2_preprocess_page(&$vars){
    //http://www.zites.net/en/load-external-javascript-files-drupal-6/
    $external_js1 = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js';
   drupal_add_js('document.write(unescape("%3Cscript src=\''. $external_js1 .'\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline');
    $external_js2 = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js';
   drupal_add_js('document.write(unescape("%3Cscript src=\''. $external_js2 .'\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline','header');
    $external_js3 = 'http://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.2/masonry.pkgd.min.js';
   drupal_add_js('document.write(unescape("%3Cscript src=\''. $external_js3 .'\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline');
   drupal_add_js(drupal_get_path('theme', 'd6_ce_susy2') . '/js/jquery_init.js','theme');
   drupal_add_js(drupal_get_path('theme', 'd6_ce_susy2') . '/js/js_jquery_new.js','theme');  
   drupal_add_js(drupal_get_path('theme', 'd6_ce_susy2') . '/js/jquery_exit.js','theme');
   drupal_add_js(drupal_get_path('theme', 'd6_ce_susy2') . '/js/js_jquery_defaut.js','theme');
      }

1 Answer 1

0

You can below preprocess function with scope and weight. You would need to set scope as footer and add the variable to html.tpl.php before body tag.

function paddle_theme_preprocess_html(&$variables) {
  drupal_add_js(drupal_get_path('theme', 'paddle_theme') .  '/scripts/footer.sticky.js',
  array(
    'type' => 'file',
    'scope' => 'header',
    'group' => JS_THEME,
    'every_page' => TRUE,
    'preprocess' => FALSE,
  ));
}

Also for Drupal 6, you can check the following reference with Advance JS aggregation or LABjs which can do the parallel loading.

http://www.drupalden.co.uk/move-render-blocking-javascript-bottom-page

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.