Hi,

I have a lot of background images on my site - is it advisable to reference another sub-domain for some of them (http:// etc instead of relative paths in the css file itself) or would that cause problems with this module?

Thanks,
Paul.

Comments

mikeytown2’s picture

Remember that testing & benchmarking is key.

You can put in absolute paths in the CSS file; should work without a problem!

techypaul’s picture

Hey,

I just logged in to update this - I knocked off 3 seconds just by adding a new bck.example.com and linking select background files that appear on all pages, leaving sprites and other more specific files to load as normal css. Really I wanted to make sure I wouldn't cock it up, but this is working amazingly :)

Paul.

kentr’s picture

Mind detailing why you only used the second domain for some of the bg images?

I'm guessing that as long as you didn't overload the second domain, you'd see further improvements by offloading more requests to that domain, so I'd like to know if there's something I'm missing here.

kentr’s picture

@mikeytown2:

Idea for converting the CSS background image URLs in the CSS files.

  1. Have a helper script in the module directory, something like css.php.
  2. Convert CSS <link> URLs to http://cdn1.example.com/path/to/parallel/css.php?file=path/to/css/example.css
  3. In css.php, process example.css to transform the URLs and spit out the result.
  4. And of course, use all the usual caching tricks...
dman’s picture

Issue tags: +optimization

Just speculating here, but as the HTTP spec allegedly limiting the number of concurrent HTTP requests to the same domain, (two at a time according to a short summary on browser load order), you'll get most significant results by splitting the requests something close to 50:50. Best if you somehow pair the loading images in an alternating way :-)
So there may be logic in sharing it out.

That's just imagining of course, and you need real benchmarks and http introspection to see what's really happening.

Note, even using an alias to your same site will give you the boost to get by the 'concurrent requests' limitation, and Drupal .htaccess will respond immediately for known files if possible.
edit I see that this is what parrallel is :-) - I just dropped in from the global issue queue! heh.

RE @kentr solution to using a CDN - if the php step is entirely neccessary (can't you just nominate an URL directly?) then be sure to remember to set the correct cache headers! A PHP query-based request each time may work against any caching wins. In theory, a GET may hang around in cache, but caches may be tuned to favor longer-term memory of *.gif than of *.php?query type requests.

mikeytown2’s picture

I'm personally against a css.php file, even though Boost could cache it (currently it doesn't ATM). Better control over what goes in the css file is currently out of the scope of this project (it could change in the future). Things that build the CSS file would be better suited for injecting different domains in the css file.

http://drupal.org/project/modules?filters=drupal_core%3A87%20tid%3A73&te...

If there's some sort of API that easily allows the manipulation of the contents of the CSS file, specifically url() let me know, might make this much easier to implement. As of right now coding up a CSS manipulation function is something I do not want to focus on, using an API on the other hand I'm open to.

techypaul’s picture

Hey,

I am not around right now to check, but I think you can use upto 4 domains without causing problems. I used bck for my manually selected css images, img. for my front ground images and txt for css file (and non bck images). everything else was from the main domain. I manually selected specific background images that were large but not likely to be called on the same page, that way they wouldnt hold each other up. It worked well for me.

I tried different settings and options but this worked best for me (as they, testing is key!).

Thanks,
Paul.

wim leers’s picture

I had written this functionality (updating URLs in CSS files) as part of the first version of the CDN integration module for Drupal 5, two years ago now. You can steal the code from there if you want to.

A better solution is to use the File Conveyor daemon in combination with the CDN integration module.

philbar’s picture

You might also be interested in CSS Embedded Images if the images are small (less the 32kb).

wim leers’s picture

Status: Active » Closed (fixed)