diff --git a/advagg.module b/advagg.module
index ec96557..7a2cf78 100755
--- a/advagg.module
+++ b/advagg.module
@@ -270,58 +270,10 @@ function advagg_admin_menu_output_alter(&$content) {
  * Implementation of hook_cron().
  */
 function advagg_cron() {
-  if (!variable_get('advagg_prune_on_cron', ADVAGG_PRUNE_ON_CRON)) {
-    return;
-  }
-
-  // Set the oldest file/bundle to keep at 2 weeks.
-  $max_time = module_exists('advagg_bundler') ? variable_get('advagg_bundler_outdated', ADVAGG_BUNDLER_OUTDATED) : 1209600;
-  $max_file_time = time() - $max_time;
-  $max_bundle_time = time() - ($max_time*3);
-  $bundles_removed = 0;
-  $files_removed = array();
-
-  // Prune old files
-  $results = db_query("SELECT filename, filename_md5 FROM {advagg_files}");
-  while ($row = db_fetch_array($results)) {
-    // If the file exists, do nothing
-    if (file_exists($row['filename'])) {
-      continue;
-    }
-
-    // Remove bundles referencing missing files, if they are older than 2 weeks.
-    $bundles = db_query("SELECT bundle_md5 FROM {advagg_bundles} WHERE filename_md5 = '%s' AND timestamp < %d", $row['filename_md5'], $max_file_time);
-    while ($bundle_md5 = db_result($bundles)) {
-      $bundles_removed++;
-      db_query("DELETE FROM {advagg_bundles} WHERE bundle_md5 = '%s'", $bundle_md5);
-    }
-    $count = db_result(db_query("SELECT COUNT(*) FROM {advagg_bundles} WHERE filename_md5 = '%s'", $row['filename_md5']));
-
-    // If no more bundles reference the missing file then remove the file.
-    if (empty($count)) {
-      db_query("DELETE FROM {advagg_files} WHERE filename_md5 = '%s'", $row['filename_md5']);
-      $files_removed[] = $row['filename'];
-    }
-  }
-
-  // Prune old bundles
-  $bundles_removed += db_result(db_query("
-    SELECT COUNT(*)
-    FROM (
-      SELECT *
-      FROM {advagg_bundles}
-      WHERE timestamp < %d
-      GROUP BY bundle_md5
-    ) AS advagg_count", $max_bundle_time));
-  $results = db_query("DELETE FROM {advagg_bundles} WHERE timestamp < %d", $max_bundle_time);
-
-  // Report to watchdog if anything was done.
-  if (!empty($bundles_removed) || !empty($files_removed)) {
-    watchdog('advagg', 'Cron ran and the following files where removed from the database: %files <br /> %count old bundles where also removed from the database.', array(
-      '%files' => implode(', ', $files_removed),
-      '%count' => $bundles_removed,
-    ));
+  if (variable_get('advagg_prune_on_cron', ADVAGG_PRUNE_ON_CRON)) {
+    advagg_prune_old_bundles();
   }
+  advagg_remove_empty_files();
 }
 
 /**
@@ -402,6 +354,111 @@ function advagg_theme_registry_alter(&$theme_registry) {
 }
 
 /**
+ * Remove old bundles and files to keep things tidy.
+ */
+function advagg_prune_old_bundles() {
+  // Set the oldest file/bundle to keep at 2 weeks.
+  $max_time = module_exists('advagg_bundler') ? variable_get('advagg_bundler_outdated', ADVAGG_BUNDLER_OUTDATED) : 1209600;
+  $max_file_time = time() - $max_time;
+  $max_bundle_time = time() - ($max_time*3);
+  $bundles_removed = 0;
+  $files_removed = array();
+
+  // Prune old files
+  $results = db_query("SELECT filename, filename_md5 FROM {advagg_files}");
+  while ($row = db_fetch_array($results)) {
+    // If the file exists, do nothing
+    if (file_exists($row['filename'])) {
+      continue;
+    }
+
+    // Remove bundles referencing missing files, if they are older than 2 weeks.
+    $bundles = db_query("SELECT bundle_md5 FROM {advagg_bundles} WHERE filename_md5 = '%s' AND timestamp < %d", $row['filename_md5'], $max_file_time);
+    while ($bundle_md5 = db_result($bundles)) {
+      $bundles_removed++;
+      db_query("DELETE FROM {advagg_bundles} WHERE bundle_md5 = '%s'", $bundle_md5);
+    }
+    $count = db_result(db_query("SELECT COUNT(*) FROM {advagg_bundles} WHERE filename_md5 = '%s'", $row['filename_md5']));
+
+    // If no more bundles reference the missing file then remove the file.
+    if (empty($count)) {
+      db_query("DELETE FROM {advagg_files} WHERE filename_md5 = '%s'", $row['filename_md5']);
+      $files_removed[] = $row['filename'];
+    }
+  }
+
+  // Prune old bundles
+  $bundles_removed += db_result(db_query("
+    SELECT COUNT(*)
+    FROM (
+      SELECT *
+      FROM {advagg_bundles}
+      WHERE timestamp < %d
+      GROUP BY bundle_md5
+    ) AS advagg_count", $max_bundle_time));
+  $results = db_query("DELETE FROM {advagg_bundles} WHERE timestamp < %d", $max_bundle_time);
+
+  // Report to watchdog if anything was done.
+  if (!empty($bundles_removed) || !empty($files_removed)) {
+    watchdog('advagg', 'Cron ran and the following files where removed from the database: %files <br /> %count old bundles where also removed from the database.', array(
+      '%files' => implode(', ', $files_removed),
+      '%count' => $bundles_removed,
+    ));
+  }
+}
+
+/**
+ * Scan all generated bundles for empty content and remove it from output.
+ */
+function advagg_remove_empty_files() {
+  // Get the filetype paths.
+  list($css_path, $js_path) = advagg_get_root_files_dir();
+
+  // Get a list of all bundles from the DB.
+  $results = db_query("
+    SELECT
+      af.filetype,
+      ab.bundle_md5,
+      ab.counter
+    FROM advagg_bundles AS ab
+    INNER JOIN advagg_files AS af USING (filename_md5)
+    GROUP BY bundle_md5
+  ");
+
+  $files = array();
+  while ($row = db_fetch_array($results)) {
+    $row['filename'] = advagg_build_filename($row['filetype'], $row['bundle_md5'], $row['counter']);
+    if ($row['filetype'] == 'css') {
+      $row['filepath'] = $css_path . '/' . $row['filename'];
+    }
+    if ($row['filetype'] == 'js') {
+      $row['filepath'] = $js_path . '/' . $row['filename'];
+    }
+    $files[] = $row;
+  }
+
+  // Find the empty files.
+  $empty_list = array();
+  foreach ($files as $fileinfo) {
+    // Skip if the file is not readable.
+    if (!file_exists($fileinfo['filepath']) || !is_readable($fileinfo['filepath'])) {
+      continue;
+    }
+
+    $contents = trim(file_get_contents($fileinfo['filepath']));
+    if (empty($contents) || $contents == 'html {display:block;}') {
+      $empty_list[] = $fileinfo;
+    }
+  }
+
+  // Return if there are no empty files.
+  if (empty($empty_list)) {
+    return;
+  }
+
+}
+
+/**
  * Get the CSS & JS path for advagg.
  *
  * @param $reset
