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');
      }

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

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

  • unfortunately it isn't possible with D6.. :/ – webmaster pf Oct 28 '15 at 10:11
  • this module : drupal.org/project/advagg could be a way to manage loading order...testing it – webmaster pf Oct 28 '15 at 10:36
  • Finally i include external JS by classic way to my header, before the script function of drupal. – webmaster pf Oct 30 '15 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.