Drupal CSS optimization failed


My colleague Gaurav he is Drupal expert, is working on a Drupal project. He has almost completed the project so now the time was to switch the project from development to production environment. In the development environment we have Windows Xp, Apache2.2.17, PHP 5.2 and MySQL 5.0.7 and on production environment we have the same PHP, the same Apache, the same MySQL and Windows 2003.

I helped him during server configuration and deployment, everything deployed successfully we were able to see the site. But when he turned on the CSS and JS optimization from admin->performance setting in drupal.

Browser was going nowhere we were just getting the message “Page can not be displayed”. Why we don’t know, because there was no any apache error log, no any php error log. Finally we came to know that CSS optimization is creating an issue, the reason was drupal optimizer was not able to create CSS cache file in sites/default/files/css folder. Whereas JS cache was created in sites/default/files/js folder.

Then we again disabled the CSS optimization, (just only CSS optimization because JS optimization was working very well), now we tried to access the site this time it rendered properly, but only with firefox. Not with IE, this time the reason was clear, because IE only allows 31 CSS request at a time and we were having 34 CSS. We could reduce the CSS requests by disabling few unused modules but it was not a solution to our problem.

Everything was okay but without solving this issue we would not be able to say that everything is working very well. We spent almost two days to find out the reason and solution. Finally I found a solution on Drupal issues page. I found that this is not a strange issue many drupal expert has already faced this. Here is the link to the post

http://drupal.org/node/444228

Somebody has posted a patch for common.inc file which basically does the optimization work, here is the patch

http://drupal.org/node/444228#comment-2095622

So open common.inc file find this code and replace it (offcourse to play safely, first do a backup)


if ($_optimize) {
// Perform some safe CSS optimizations.
$contents = preg_replace('< - \s*([@{}:;,]|\)\s|\s\()\s* | # Remove whitespace around separators, but keep space around parentheses. /\*[^*\\\\]*\*+([^/*][^*]*\*+)*/ | # Remove comments that are not CSS hacks. [\n\r] # Remove line breaks. >x', '\1', $contents);
}

I hope this will help you guys if you work someday on Drupal and face the same issue 🙂 which is very rare.

Cheers,
Jaswant

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s