Off-loading wpmu theme files to Amazon-S3

I saw a few people looking for solutions to off-load wpmu files to Amazon-S3 service. This is something we wanted to try on our installation (just a few thousand blogs) so I wrote a plugin that will serve themes css and image files from S3.

The plugin uses the ‘stylesheet_directory_uri‘ filter to set the stylesheet uri (css file). In turn, the stylesheet uses the ‘url‘ method to call the image files of the theme so they get the same base url as the stylesheet. Most themes uses the ‘stylesheet_directory‘ call correctly so you will not run into trouble but if a theme uses it to call a php file you should change the call to use ‘template_directory‘.

Download: themes-s3.zip

Usage:

  1. Signup for an Amazon-S3 account.
  2. Create a bucket for your files. Since you have to select a globally unique name for your buckets I call it s3.domain.com were domain.com is my wpmu installation.
  3. To point s3 to your bucket setup a CNAME record: s3 -> s3.domain.com.s3.amazonaws.com. (don’t forget that extra dot at the end).
  4. Load your themes css and image files to your bucket keeping the exact directory structure for each theme (/wp-contents/themes/… ). You can use the excellent S3 FireFox Organizer to mange your files.
  5. Edit the plugin to include your bucket name.
  6. Place the plugin in the mu-plugins directory.
  7. Test, test and test all your themes!

Whats next? The next step I’m planning is to off-load the Java Scripts in the wp-includes folder. Also planned is an option to serve the users files from S3. If you are interested in helping in any way please leave a comment and we can take it from there.


Did you find this post interesting? Please subscribe to my feed.

11 Responses to “Off-loading wpmu theme files to Amazon-S3”

  1. Great idea. Offloading the wp-includes statics to s3 is something I already done but I didn’t do it as a plugin and just hardcoded it in.

  2. Hone, I rather not hardcode things in the core files. Would you like to share the changes you made?

  3. notice any speedboost?

  4. suleiman,
    I would not say speedboost but this is one of the measures we take to reduce the stress on the server (caching would be anther one).

    btw, your home page is great, did you share your nice mootools effects ?)

  5. Elad,

    Thanks for the kind words. I haven’t shared my homepage, at least not in a nice downloadable form, primarily because it’s not pretty code. You can of course download all of the necessary scripts to make those funky animations from the mootools homepage.

    With respect to speedboosts, I’ve been working hard on optimizing my site load times over the past couple of weeks, including setting up APC, wp-super-cache, and boosting mysql cache. My next step is to try and figure out how to get gzip encoding to work. Have you had any luck with that?

  6. suleiman,
    For caching we use super-cache. I did made a hack so the cache will be cleared when a user updates his widgets.

    Why would go want to gzip? This may save you bandwidth but that is not an issue, or is it?

  7. Elad, I didn’t really make notes.

    I set up an s3 bucket an cnamed a subdomain there like assets.yourdomain.com.

    Then I did a find and replace in script-loader.php and placed the subdomain before every .js file.

    It’s a pretty sucky way of doing it. But it only took me a minute to change the file with find and replace.

    With Nginx you can actually set it up to proxy any requests to /wp-includes/js/ to an s3 bucket. That way it appears as though your javascript is coming from http://yourdomain.com/wp-includes/js/script.js when really its being served by an s3 bucket.

  8. Elad, just to update you, I did end up getting GZIP compression working. Not only does it cut down on bandwidth requirements, but it also boosts page load time by 2-3 times. I strongly recommend it.

  9. Suleiman, sounds great!
    How did you do it? Is it with the super-cache plugin settings?

  10. [...] Off-loading wpmu theme files to Amazon-S3 | Ring Of Blogs [...]

  11. [...] Ring Of Blogs blogging, wordpress-MU, monetization and stuff… « Off-loading wpmu theme files to Amazon-S3 [...]

Leave a Reply