February 4, 2012

Tricky Drupal Javascript Loading Problem

drop Tricky Drupal Javascript Loading ProblemA short tale about squashing a bug.

You see, my mistrust for IE made me miss the real problem. What was happening was that in IE 7 on Vista, a site I’m building for a client was not loading any Javascript. It wasn’t even loading the base Javascript "jquery.js" and "drupal.js", so my site theme Javascript wasn’t working at all.

I dug in and began tracing code using my typical technique of embedding "drupal_set_message()" calls in the suspect areas. Sure enough, no Javascript was getting loaded, but only when I used my IE test machine.

The cause

I was not logged-in on the IE machine. So Drupal didn’t think I needed any Javascript. Nowhere in the code was "drupal_add_js(anything.js)" called since I didn’t have any modules that needed any Javascript.

In that case, Drupal doesn’t load any Javascript at all, so none was loaded. It was a feature, not a bug.

The fix

I just enabled one of the modules that I had been planning to use anyway, which uses the "drupal_add_js(anything.js)" call. Suddenly my IE testbox worked fine.

For once, it really wasn’t IE at fault. Amazing.

[tags]drupal,javascript[/tags]

Share and Enjoy:
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem
  • services sprite Tricky Drupal Javascript Loading Problem

Related posts:

  1. Javascript Programming Conventions I’ve been meaning to write a Javascript “best practices” style...
  2. Taxonomy Theme, how I love thee I'm building a new Drupal 5 site for a client,...

About Bruce Kroeze

Comments

  1. tim says:

    So… how did you fix it?

  2. levin says:

    What do you mean by logged in? Logged in to the Drupal site?

    Does your theme print html that should load javascript, but drupal throws it out if it’s not loaded through the drupal_add_js function? I guess this must have been drupal 5 you were talking about?

Speak Your Mind

*