How to use Drupal with CDN providers like Akamai ?

I want to publish the photos, audio, video uploaded by users to a CDN provider's servers (akamai) to reduce the traffic from the drupal servers from serving rich content. Has anyone done this and what it would take to change the modules to do this?

Is it simply changing the storage location from file system to a URL?

Thanks - a newbie who loves drupal

David

I would love to know as well

ablemike - July 18, 2007 - 23:17

This is huge a debate here!

Akamai for audios and videos

xmacinfo - July 19, 2007 - 02:11

For video, you will have to publish them on your site like a regular video file (or audio file). For example, a "akamai-ready.mov" will need to be saved locally on your Drupal web site. So any Drupal video module will do the work.

The Akamai-ready video (and audio) files are in essence a simple XML file embedding URL pointing to Akamai reflectors. The end user thinks he is downloading from your site.

So, yes, you can use Drupal with a CDN like Akamai.

I haven't done any photo through Akamai, though. However, I'm sure you can use Drupal safely for these types of files.

Thanks

davidslee9 - July 19, 2007 - 02:46

Glad to hear it can work. Can you be more specific on how this would be done?

Thanks
David

By the way, CDN's are

ericatkins - July 26, 2007 - 17:43

By the way, CDN's are Yahoo!'s number 2 way or increasing performance on your website: http://developer.yahoo.com/performance/rules.html#cdn

Actually, here are Yahoo!'s suggestions:

1. Make Fewer HTTP Requests
2. Use a Content Delivery Network
3. Add an Expires Header
4. Gzip Components
5. Put CSS at the Top
6. Move Scripts to the Bottom
7. Avoid CSS Expressions
8. Make JavaScript and CSS External
9. Reduce DNS Lookups
10. Minify JavaScript
11. Avoid Redirects
12. Remove Duplicate Scripts
13. Configure ETags

---
the Hushed Casket | Eric Atkins

Akamai module

mikiane - September 7, 2007 - 11:06

At France 24 we are creating an Akamai module to allow Drupal to be correctly
cached by Akamai caching services. We encountered problems caching the
result of some form posts.

Ex: an internet user post a comment. The page displayed does not
contain the confirmation message that indicates the comment has been
submitted...

We have created a module that hooks every submit function used by
Drupal. When a submit is done, Drupal makes a redirect to the orginial
page. On this redirect we add a querystring "?bypass=1" And we
configure Akamai for not caching pages that contains ?bypass=1

We will publish this module xhen it will be correctly tested.

Hi there, is there any

Schneck - May 29, 2008 - 09:04

Hi there,

is there any progress developing this module? If there's a alpha/beta, could you publish a snapshot? I'm very interested in using it and maybe could provide help at development.

Bye,
Stefan

Did you find this CDN module?

Dru-p - August 14, 2008 - 00:57

Stefan,

Did you find this CDN module? http://drupal.org/project/cdn

The author's website says he has plans to improve/upgrade to D6 too. (I would like to use it with D6 as I understand that it already puts multiple css/js files from modules into single css/js files, which much improves perceived page loading speed.)

Not sure if this is important to you, but from memory it's not for Akamai, but another provider CacheFly?

I also read that another project that the author is involved with uses a provider called SimpleCDN.com, and rates them highly, so perhaps the D6 port will work with them out of the box?

Fingers crossed that he has some spare time or a sponsor :)

Yes, I saw the CDN-Module,

Schneck - August 14, 2008 - 08:31

Yes, I saw the CDN-Module, but it didn't work for me/Akamai.
I wrote a dirty workaround that checks the referer and, depending on it, leads the user on to the source server or the CDN-mirror. I have to say, my scenario isn't that complicated: all files (sites, media files) are fetched either completely from a source server or completely from a mirror, depending on the server load, so it's easy to switch the complete traffic from one server to the other.

potential solution to use with boost

cdoyle - December 11, 2008 - 21:42

If you are able to use static page caching that the boost module (http://drupal.org/project/boost) provides, I have a possible solution for you. It's something I've been playing around with and doing some load testing on but it seems like it could work. Boost generates static html pages of your content and lets you hook a pre-process function in (under admin/settings/performance/boost advanced settings).

I wrote this pre-processing function that changes the relative urls to absolute urls that would be pointed at the CDN content. This function changes links to javascript, css, your shortcut icon, and image files to be served off the CDN. It should be fairly trivial to modify this function to change links to your files or anything else. You would also either need to hard code in the cdn url (e.g. "http://cdn.yoursite.com/") to the 'yoursite_cdn_url' variable or you will need to add a place to set this in your site settings.

/**
* This function takes in a staticly rendered page and replaces the relative
* urls with absolute urls (potentially) pointing at an alternate CDN host
* like Akamai.  Place this in a site specific module or possibly in your template.php
* in your theme.
*/
function yoursite_preprocess_boost($data) {
  $cdn_url = variable_get('yoursite_cdn_url', "http://{$_SERVER['HTTP_HOST']}/");  // falls back on current site

  $patterns[] = '/\<script type="text\/javascript" src="\//';
  $replacements[] = '<script type="text/javascript" src="' . $cdn_url;

  $patterns[] = '/\<style type="text\/css" media="(.+?)"\>\@import "\//';
  $replacements[] = '<script type="text/css" media="${1}">@import "' . $cdn_url;

  $patterns[] = '/\<link rel="shortcut icon" href="\//';
  $replacements[] = '<link rel="shortcut icon" href="' . $cdn_url;

  $patterns[] = '/\<img(.+?)src="\/(.+?)\>/';
  $replacements[] = '<img${1}src="' . $cdn_url . '${2}>';

  $data = preg_replace($patterns, $replacements, $data);

  return $data;
}

If you don't want to use boost, you might be able to write a input format filter that would do a similar thing. I haven't evaluated what the performance hit would be for this. Is there any news about this akamai module that was mentioned above?

Quick and dirty way to use css cdn (eg., YUI)

chris_s - January 23, 2009 - 05:05

This may be too obvious to merit mention, but...

drupal_add_css doesn't (seem to) work with absolute urls, so I'm simply coding the link in the section of my page.tpl.php file. There may be a more elegant/standard way to accomplish this -- if so, please do tell!

EG: (in mytheme/page.tpl.php)

<head>
  <title><?php print $head_title ?></title>
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <?php print $head ?>
  <?php print $styles ?>
  <link type="text/css" rel="stylesheet" media="all" href="http://yui.yahooapis.com/2.6.0/build/reset-fonts-grids/reset-fonts-grids.css" />

  <?php print $scripts ?>
</head>

The simpleCDN module is

parrottvision - April 23, 2009 - 23:50

The simpleCDN module is brilliant - the only problem is that simpleCDN (the service not the module) have changed the way they do things and no longer offer a mirror service from the end of April. So I will be seeing if something like CacheFly will work with the module instead.

I did a write up on the simpleCDN module here:
http://www.markparrott.com/blog/drupal-website-performance-improve-your-...

See the project page here:
http://drupal.org/project/simplecdn

Note: simpleCDN Module and the simpleCDN service are not directly related in anyway.

Drupaling along...
feed me deals

UPDATE - simpleCDN restarted

parrottvision - September 1, 2009 - 22:03

UPDATE - simpleCDN restarted a service called lightening which does work with the simpleCDN module again - I guess they realised how silly it was to change the previous service. It's dirt cheap and provides a mirror on the fly service which is brilliant and super cheap. You can just create a bucket - take the URL and put it in the simpleCDN module and your sorted. I also serve my CSS and some JS files through it also.

Drupaling along...
feed me deals

 
 

Drupal is a registered trademark of Dries Buytaert.