How to conditionally load a javascript or css? I just got assigned to a project that requires bug fixes. It is not a bug, but the client is asking us to reduce size of our site's compressed javascript.

I found out that the compressed js' size is around 500kb, which is pretty big. I think it is that big because Drupal loads all the javascript from all the enabled modules. The problem is that there are scripts that I don't use on my homepage or other pages.

What would be a good solution or workaround for my issue? One thing I can think of is to turn off compreconditionally disable modules in my template...but...is that okay or even possible?
What your looking to do is remove extra JS or CSS files, correct? AdvAgg can do this for you.
hook_advagg_js_pre_alter()
hook_advagg_css_pre_alter()
are the hooks you want to implement. Then inside of the hook you can use the arg() function to figure out what page your on.

$args = arg();
if (   isset($args[0]) &amp;&amp; $args[0] == 'node'
    &amp;&amp; isset($args[1]) &amp;&amp; is_numeric($args[1])
    &amp;&amp; !isset($args[2])
      ) {
  $node = node_load($args[1]);
  if (!empty($node) &amp;&amp; $node-&gt;type == 'page') {
    // Do awesome stuff to the JS/CSS array.
  }
}


See advagg_js_cdn_advagg_js_pre_alter() for an example on how the hook is used. Also be aware of drupal_is_front_page(); it might be useful.