I am currently starting development of drupal sites on Acquia. Using git and working locally is a new workflow for me. When building locally and trying to utilize Modernizr load / yepnope, my JS in my script.js file typically looks like this..

    test: Modernizr.mq('only all'),
    nope: '/sitename/docroot/sites/all/themes/theme/js/libs/polyfill.js'

So that works locally on my machine, but when I commit my changes and push to my acquia development server the file path for the loaded scripts is incorrect, since it's not the same setup I guess.


It needs to be the below, without the mysite/docroot in the URL.


So that brings me to Drupal.settings.basePath. If I print this out it gives me /mysite/docroot/ on my local setup. If I do it on the dev server, it would print out something different (probably just / ).

So me being the amateur assumed I could do something like this.. (forgive the poor sample, I know it can be done better)

var myroot = Drupal.settings.basePath

test: Modernizr.mq('only all'),
nope: myroot + 'sites/all/themes/theme/js/libs/polyfill.js'

And this of course does not work. Just returns query1 is not defined.

So I am sure there are faults in many of my attempts to make this work.. so if anyone can suggest something to me, either workflow related or how to fix my setup / code, that would be great.



Your local environment seems to be misconfigured. If you're running apache with vhosts then your VirtualHost definition should look like this:

<VirtualHost *:80>
  ServerName whatever-you-choose-for-a-dev-domain.com
  DocumentRoot "/path/to/the/drupal/root/directory"

Where the DocumentRoot should also include /sitename/docroot

Alternatively you may be able to edit .htaccess in the Drupal root directory to RewriteBase /sitename/docroot Which there should already be a commented definition of RewriteBase in there that you simply would uncomment. But I think the VirtualHost path would be the best one.

  • This is good info, as it does work if you are using a VirtualHost definition (I personally am, but I am taking into consideration that most people are not using a virtual host) – briggimus Feb 3 '13 at 21:41

Here is what I do

    //first test need for polyfill
        test: window.matchMedia,
        nope: (Drupal.settings.basePath + Drupal.settings.pathToTheme + "/js/polyfills/matchMediajs/matchMedia.js")

    //and then load enquire
    (Drupal.settings.basePath + Drupal.settings.pathToTheme + '/js/enquirejs/dist/enquire.min.js')

In my template.php I have the following in my _preprocess_page function:

drupal_add_js(array('pathToTheme' => path_to_theme()), 'setting');
  • I tried implementing this but have some issues. – briggimus Feb 3 '13 at 21:30
  • Sigh. Silly 5 minute comment rule. I tried implementing this but have some issues. t Found) mysite.devcloud.acquia-sites.com/NaNsites/all/themes/my_theme/… As you can see I get an NaN in the src url. I am using the Omega theme so that means I have a preprocess-page.inc file that I added the drupal_add_js line to. – briggimus Feb 3 '13 at 21:37

As far as I can tell this is a Drupal core bug in drupal_get_js(). The issue seems to be that the Drupal.settings information is actually inserted after all library, module, and theme JavaScript. According to the documentation of drupal_add_js(), Drupal.settings should be added to the JS_LIBRARY group which has a weight of -100, whereas theme javascript has a weight of 100 and should go after the settings in the source order.

There is a one line patch at http://drupal.org/node/1710002 or you can try this workaround. The workaround assumes that your JavaScript will still work as expected in the footer (just before the </body>.

  1. Remove the scripts[] = js/myscript.js from your theme's .info file.

  2. In template.php, add the drupal_add_js() line to your existing hook_preprocess_page() or add this new function:

     * Implements hook_preprocess_page().
    function MYTHEME_preprocess_page(&$variables) {
      drupal_add_js(path_to_theme() . '/js/myscript.js', array('scope' => 'footer'));

If you use the APIs available inside the Modernizr Drupal module, it takes care of requesting the proper path for you. Here are some docs:


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.