This is a strange one... javascript_aggregator is doing its thing. The .jsmin.js files are being created, and the $scripts variable appears to be updated correctly in preprocess_page to reference the minified version rather than the standard one. However, when the $scripts variable is printed in my page.tpl template, the non-minified version is output. The strange thing is that I have tried inserting a dsm() call to show me the contents of $scripts right before the line that prints it in page.tpl, and I can see that it DOES reference the minified version. But on the very next line when the $scripts variable is printed to the stdout, it references the non-minifed version, and that is what my browser gets! Any ideas what could be going here?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

update: ok, so I had a caching issue which was skewing this a little and after disabling all of my caches, doing a dsm of $secript in page.tpl itself actually does show that it references the non-minified version... I have since managed to get javascrip_aggrigation to work, but only by adding this in my theme's template.php:

function mytheme_preprocess_page(&$vars) {
$vars['scriptsmin'] = $vars['scripts'];
}

and then referencing $scriptsmin in page.tpl.

So, when my theme's preprocess_page function is run, $scripts contains the correct js, but at some point between here, and actually printing the variable, it is being reset.

derjochenmeyer’s picture

Status: Active » Needs review
FileSize
932 bytes
1.02 KB

Do you have jquery_update installed?

We need to do 2 things in order to keep Javascript Aggregator working.

  1. Add an .install file that set the modules weight very high (e.g. 9999) in order to run after all modules
  2. jQuery Update uses hook_theme_registry_alter to run its preprocess_page hook after all other modules
    /**
     * Implementation of hook_theme_registry_alter().
     *
     * Make jQuery Update's page preprocess function run *after* everything else's,
     * so that a theme can't call drupal_get_js() and mess everything up.
     */
    function jquery_update_theme_registry_alter(&$theme_registry) {
      if (isset($theme_registry['page'])) {
        // If jquery_update's preprocess function is there already, remove it.
        if ($key = array_search('jquery_update_preprocess_page', $theme_registry['page']['preprocess functions'])) {
          unset($theme_registry['page']['preprocess functions'][$key]);
        }
        // Now tack it on at the end so it runs after everything else.
        $theme_registry['page']['preprocess functions'][] = 'jquery_update_preprocess_page';
      } 
    }
    

    We can do the same

    /**
     * Implementation of hook_theme_registry_alter().
     *
     * Make javascript_aggregator's page preprocess function run *after* everything else's (even jQuery Update),
     * so that a theme can't call drupal_get_js() and mess everything up.
     */
    function javascript_aggregator_theme_registry_alter(&$theme_registry) {
      if (isset($theme_registry['page'])) {
        // If javascript_aggregator's preprocess function is there already, remove it.
        if ($key = array_search('javascript_aggregator_preprocess_page', $theme_registry['page']['preprocess functions'])) {
          unset($theme_registry['page']['preprocess functions'][$key]);
        }
        // Now tack it on at the end so it runs after everything else.
        $theme_registry['page']['preprocess functions'][] = 'javascript_aggregator_preprocess_page';
      } 
    }
    

Attached is an .install file and a patch for javascript_aggregator.module (6.x-1.x-dev, 2009-Mar-23) which sould solve this issue.

To get this working:

  1. patch javascript_aggregator.module (or add function javascript_aggregator_theme_registry_alter from above manually)
  2. extract javascript_aggregator.install to your javascript_aggregator directory
  3. run update.php

Please test.

derjochenmeyer’s picture

Assigned: Unassigned » derjochenmeyer
derjochenmeyer’s picture

Fixing the comment of hook_theme_registry_alter for Javascript Aggregator inspired by jQuery Update. Use in combination with javascript_aggregator.install from #2.

jannalexx’s picture

nice, same issue
and your patch/install mod did the trick (latest dev)
combined with CSS Gzip, I just saved 200k css/js from my front page, verycool...

derjochenmeyer’s picture

Thanks for your feedback. I'll include it in the next release of Javascript Aggregator.

Anyone else who tried this patch? Please test.

derjochenmeyer’s picture

Status: Needs review » Fixed

Added this to current dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.