Java Script

- Drupal comes with the jQuery JavaScript library ( in cluded in core, so you have access to all of the jQuery goodness without ' i y needing to add the library yourself.

CSS and JavaScript Optimization Settings

Because of Drupal's modular nature, even a relatively simple site can end up with many CSS and JavaScript files included on any given page. In a default Drupal 6 installation, the CSS and JavaScript tags included in the HTML of the content editing page (with no extra modules enabled) comes to seven CSS files and six JavaScript files! And this number expands quickly when installing and enabling more modules.

By visiting the Performance settings page at Administer^Site configuration^Perform-ance (admin/settings/performance), you can enable CSS and JavaScript optimization. This option joins all of the CSS files for a given page into one optimized file with comments and extra whitespace removed. JavaScript gets a similar treatment. Instead of the 13 files that we were including originally, after optimization we now get only these 4 lines:

<link type="text/css" rel="stylesheet" media="all"

href="/drupal/sites/default/files/css/7f66dbf90ba0323c5d322cde426f75ed.css" /> <link type="text/css" rel="stylesheet" media="print"

href="/drupal/sites/default/files/css/bf2acfbc35fa1d13cbc410a9bdc36563.css" /> <script type="text/javascript"

src="/drupal/sites/default/files/js/45caa15f0935ad439814b66bcdf4b022.js"></script> <script type="text/javascript">jQuery.extend(Drupal.settings,

{ "basePath": "/drupal/", "teaserCheckbox": { "edit-teaser-js": "edit-teaser-include" }, "teaser": { "edit-teaser-js": "edit-body" } });</script>

Obviously, there are fewer files—which require fewer hits to your server as the browser determines whether it has the correct files in its cache. This is good stuff, and highly recommended for live sites! Just be careful not to turn this option on while you're actively developing your CSS and JavaScript.

Was this article helpful?

0 0

Post a comment