It appears that I cannot have something below in my THEME.info file:

scripts[] = http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

How can I set up a link to remote JS/CSS in .INFO file?

(My last solution is to add such links to all .tpl.php files; but I do not like this way)

Thanks,

Comments

nevets’s picture

While tempting, using remote js or css files can take a real performance hit (what happens if the server is down). So it is generally better to copy the files.

(Side note, Drupal 6.x is not designed to work with jQuery 1.4, you can use the dev version of jQuery Update to use 1.3).

minghui.yu’s picture

But I think CND or Cloud, esp those from big service provider, should be far more reliable than my own host:)

frob’s picture

I would agree with you for most third party libraries, the jquery 1.4 has CDN hosting from Microsoft and Google. I am sure their CDN is more reliable/faster/stable than my one vps.

Linking to a CDN is not the same as linking to a typical remote host.

jfine’s picture

I realize this is old but it kept coming up in the search results for me so hopefully others will find this useful.

I just skimmed the code but I think the reason remote files don't work is that the when the theme.info file gets parsed there is a dirname() call executed in order to determine the translated path and join them all for caching purposes.

There are a couple of solutions. You can either copy the page.tpl.php into your theme and manually add the stylesheet to the head. You can import the remote css in your style.css file (yuck: http://www.stevesouders.com/blog/2009/04/09/dont-use-import/). Or you can place some code in the template.php theme file. I went the template.php route, see example below. With all of these methods, don't forget to flush your cache.

# Tweak some vars in page.tpl.php
function theme_preprocess_page(&$vars) {
  # Add google fonts
  $vars['head'] .= '<link'. drupal_attributes(array(
    'rel' => 'stylesheet',
    'type' => 'text/css',
    'href' => '//fonts.googleapis.com/css?family=News+Cycle')
  ) ." />\n";
}

In Drupal >=7 you might be able to use drupal_add_css() via the template.php because it adds the 'external' $options['type'] but since I'm on 6 it would not have worked.

DrCord’s picture

I needed to add a CDN link to a JS file, I used:

function hook_preprocess_html(&$vars) {
    // Ally.js for accessibility
    drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/ally.js/1.0.1/ally.min.js', array('type' => 'external', 'scope' => 'footer'));
}