Hi,

I've examined my Drupal site and found that some javascript is loaded that is almost certainly not used. The only javascript functionality that is needed for an non-registered user is the piwik-tracking code (using this module http://drupal.org/project/piwik ).

Additionally the following javascript is loaded for an anonymous user on the front page (without any fancy blocks, etc.)
- /misc/jquery.js?3
- /misc/drupal.js?3
- /sites/default/files/languages/de_6cea9117523bf94bed165b3fc9084482.js?3

My question is, how do I find out why these files are loaded (They are about 1/4 of the total size of the front page) and how do I turn it off?

Comments

dave kopecek’s picture

You might want to take a look at the fist couple lines if piwik_reports.js:

// $Id: piwik_reports.js,v 1.1.2.9 2009/06/13 13:19:43 hass Exp $

Drupal.behaviors.piwik_reports = function() {

  var url = $("#edit-url").val();
  var page = $("#edit-page").val();

It's using Drupal.behaviors - defined in drupal.js, and jquery functions - defined in jquery.js ( note the $ ).

Might be best to leave those in.

WorldFallz’s picture

Just about anything in /misc is going to be necessary-- that's part of core.

DoctorWho’s picture

Thank you for your help.

I understand, that the jquery.js and drupal.js are from the Drupal core, but I thought it should only be loaded when needed.

@Dave
The piwik_reports.js is not loaded on every page, only piwik.js is (which is not part of the Drupal Piwik module but loaded seperately). This one does not use any Drupal-specific stuff, it just is a piece of javascript you can add to any html page to get some statistics (like Google Analytics).

So is there an easy way to find out which module/file/whatever includes the jquery.js/drupal.js so I can try to turn it off? I don't really know enough about Drupal to know where to start searching.

WorldFallz’s picture

The point is, since they're part of core lots of core functionality and much of contrib rely on it being there and loaded in the way that core loads it. Besides, jquery.js and drupal.js are already conditionally loaded.

dave kopecek’s picture

drupal_add_js will add both drupal.js and jquery.js whenever another module adds it's own javascript.

This happens in includes/common.inc, line 2099. The docs are here: http://api.drupal.org/api/function/drupal_add_js/6

That said, DON'T HACK common.inc. Just don't. You're asking for a world of hurt.

The two files really aren't that big but that's your call. If you still really want to try to remove them you might try adding a theme_preprocess_page function to your theme's templates.php. The javascript is going to be in $variables['scripts']. It will already be "rendered" into html at this point so you'll have your work cut out for you. You can use $is_front to tell if you're on the front page.

This is really not something I'd recommend.