function drupal_sort_css_js
drupal_sort_css_js($a, $b)
Sorts CSS and JavaScript resources.
Callback for uasort() within:
This sort order helps optimize front-end performance while providing modules and themes with the necessary control for ordering the CSS and JavaScript appearing on a page.
Parameters
$a: First item for comparison. The compared items should be associative arrays of member items from drupal_add_css() or drupal_add_js().
$b: Second item for comparison.
See also
File
- includes/common.inc, line 3210
- Common functions that many Drupal modules will need to reference.
Code
function drupal_sort_css_js($a, $b) { // First order by group, so that, for example, all items in the CSS_SYSTEM // group appear before items in the CSS_DEFAULT group, which appear before // all items in the CSS_THEME group. Modules may create additional groups by // defining their own constants. if ($a['group'] < $b['group']) { return -1; } elseif ($a['group'] > $b['group']) { return 1; } // Within a group, order all infrequently needed, page-specific files after // common files needed throughout the website. Separating this way allows for // the aggregate file generated for all of the common files to be reused // across a site visit without being cut by a page using a less common file. elseif ($a['every_page'] && !$b['every_page']) { return -1; } elseif (!$a['every_page'] && $b['every_page']) { return 1; } // Finally, order by weight. elseif ($a['weight'] < $b['weight']) { return -1; } elseif ($a['weight'] > $b['weight']) { return 1; } else { return 0; } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_sort_css_js/7.x