Without CSS Embedded Images:
CSS (4): 59.0K
Background Images (23): 8.9K

With CSS Embedded Images:
CSS (4): 146.4K
Background Images (7): 3.4K

This doesn't add up? Why the massive increase (87.4K) in the CSS file to add 5.5K worth of images?

I've done quite a bit of optimization on my CSS file, is it possible CSS Embedded Images has cached a version of CSS prior to my optimizations?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

philbar’s picture

I have found the following:

Base64-encoded data: URIs are roughly 33% larger in size than their binary equivalent.

But even that doesn't seem to explain the difference.

jcarnett’s picture

If you toggle CSS optimization cached CSS is rebuilt so I doubt that's the problem. It's possible that it's including multiple copies of the same image, which can happen in the 1.x version if the image is referenced multiple times in your CSS. That's not a bug, it's just a side-effect of the way the images are embedded. The 2.x version includes logic to consolidate multiple declarations into one, so you might give it a try.

Also, double-check that your numbers aren't being impacted by your browser cache. In your case 16 images have been embedded. I would usually expect that to total more than 5.5K.

If you can provide a copy of your CSS (aggregated is fine, without embedded images) or provide a link to the site it may shed a little more light on what's happening.

philbar’s picture

I'm using Yslow, so I don't think browser cache is causing the problem.

All my images are mostly rounded corners and gradients, and I compressed them using ImageOptim

philbar’s picture

FileSize
134.36 KB
126.06 KB
50.15 KB

It appears to be with the IE6 and IE7 compatibility.

Attached are my before and after css with CSS Embedded Images 6.x-2.x-dev.

Also is an html file with my Diff of the two files. Just remove the .txt that I needed to add because d.o doesn't allow css or html files to be attached.

philbar’s picture

I think the problem is you are using a very inefficient IE hack:

* html div.ctools-ajaxing,*+html div.ctools-ajaxing
{
	background:url(/sites/all/modules/ctools/images/status-active.gif) center center no-repeat;
	float:left;
	width:18px;
}

* html span.ext,*+html span.ext
{
	background:url(/sites/all/modules/extlink/extlink.png) right center no-repeat;
	padding-right:12px;
	zoom:1;
}

* html span.mailto,*+html span.mailto
{
	background:url(/sites/all/modules/extlink/mailto.png) right center no-repeat;
	padding-right:12px;
	zoom:1;
}

First, you are duplicating properties, such as "padding", "width", and "float". Shouldn't these hacks only have "background-image" property.

Also, why not create a special css file for IE6 and IE7 using conditional comments:

<!--[if IE 6]>
<link type="text/css" rel="stylesheet" media="all" href="ie6.css" />
<![endif]-->

<!--[if IE 7]>
<link type="text/css" rel="stylesheet" media="all" href="ie7.css" />
<![endif]-->
philbar’s picture

Removing all the IE hacks changed my optimized CSS file from 124.536KB to 105.472KB saving 15%.

This is still high compared to not embedding the images. The file size of that CSS is 47.578KB.

philbar’s picture

FileSize
106.68 KB

Attached is the file with no IE hacks

philbar’s picture

I created a separate issue to deal with IE conditional comments: #745520: Use Conditional Comments for IE6 and IE7 Instead of Hacks

Let's continue figuring out how 5.5K turned into 50k by embedding it.

philbar’s picture

FileSize
71.29 KB

I deleted all CSS that didn't have an image in it. I'm left with the attached file.

The problem appears to be that, I have many more images in the CSS than are being used on a regular basis.

Now I'm wondering the best way to work around this issue.

Perhaps we can implement a special code that tells CSS Embedded Images not to process certain images.

Will something like this work:

div {
   background-image:url(/misc/menu-collapsed.png); /*no-embed*/
   margin:0;
   padding:0;
}

But do comments get stripped out before CSS Embed works?

philbar’s picture

Wow, I just counted my css images. There are 79!!! I'm guessing less then 30 are typically used on a single page.

philbar’s picture

Status: Active » Needs review

There are 3 solutions I've come up with to help resolve this issue:

  1. Comment Out Unused Style from Theme - I removed comment, poll, and forum styles because I don't use those modules.
  2. Hide Authenticated User Styles from Anonymous Users - My users don't login to use my website, so I moved all warnings and edit tabs styles to admin.css and added the following to my themes page.tpl.php just after <?php print $styles; ?>:
      global $user;
      if ($user->uid) {
        echo "<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"/sites/all/themes/THEME_NAME/admin.css\" />";
      } 
  3. #745520: Use Conditional Comments for IE6 and IE7 Instead of Hacks

Without the solutions #3, I've reduced my CSS file to 116.5K. I expect as savings of around 15K with conditional comments. So my CSS should be around 100K.

After considering comment #9 you can probably change this issue to fixed. I think the suggestion in comment #9 might be a good option, because there could be background images that are used on 1 or 2 pages that shouldn't be embedded in CSS.

philbar’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.