I upgraded to 5.x-1.2 and found that specifically in my case the admin_menu module sets the defer flag on its javascript when calling drupal_add_js. So when that js is part of a bundle, the whole bundle gets the defer flag set on its script which causes a few problems on our site.

Looks like the code in sf_cache_process_file_list changed and is causing the problem. Specifically:

if ($kind == 'js') {
  $meta += array('cache' => TRUE, 'defer' => FALSE);
}

Assuming the purpose of that code is to make sure it always caches and never defers the scripts then you should be using array_merge. += on an array works the same as array_merge() but it does not override duplicate keys. So if there is already a defer = TRUE in there it will never be overwritten. Unless you wanted it to preserve the defer flag - but in that case you should really be checking to see that every file in the bundle has the defer flag.

Patch:

Index: sf_cache.module
===================================================================
--- sf_cache.module	(revision 838)
+++ sf_cache.module	(working copy)
@@ -260,7 +260,7 @@
         // Add default values to meta.
         // For CSS, $meta may currently only contain 'cc' => <conditional comments selector>
         if ($kind == 'js') {
-          $meta += array('cache' => TRUE, 'defer' => FALSE);
+          $meta = array_merge($meta, array('cache' => TRUE, 'defer' => FALSE));
         }
 
         // Add the aggregated file.

Comments

mr.j’s picture

Version: 5.x-1.2 » 6.x-1.x-dev
Status: Active » Needs review

Same patch against 6.x release.

Index: sf_cache.module
===================================================================
--- sf_cache.module	(revision 907)
+++ sf_cache.module	(working copy)
@@ -290,7 +290,7 @@
         // Add default values to meta.
         // For CSS, $meta may currently only contain 'cc' => <conditional comments selector>
         if ($kind == 'js') {
-          $meta += array('cache' => TRUE, 'defer' => FALSE);
+          $meta = array_merge($meta, array('cache' => TRUE, 'defer' => FALSE));
         }
 
         // Add the aggregated file.
mr.j’s picture

Status: Needs review » Reviewed & tested by the community

Marking reviewed and tested as I noticed this bugfix was not included in the latest dev release.

wim leers’s picture

Project: Support File Cache » BundleCache