CDN Rewrites

Note
If you are looking for the free CDN plugin, head here.

After releasing a WordPress plugin called Free CDN, I got a request from Mike Colburn to somehow extend my plugin so that rewriting hosts for commerical CDNs - those big names like Limelight, Akamai, Velocix, EdgeCast etc is supported. I am so lucky that Mike is an expert with CDNs - he even works for one of the biggest companies of the field - so with the great help from him, I’ve managed to implement this new plugin called CDN Rewrites, as I feel for Free CDN it’s a little out of scope.

Basically, CDN Rewrites allows a WordPress user to specify two important variables: an orgin host (says http://www.yoursite.com) and a “destination host” (like http://www.static.yoursite.com). It will then find all the static contents from that orgin host and rewrite them into the destination so that they will be delivered from there. For example, http://www.yoursite.com/wp-content/uploads/a-big-image.png may be rewritten into http://www.static.yoursite.com/wp-content/uploads/a-big-image.png or http://www.images.yoursite.com/a-big-image.png depending on your settings.

Because of the way it works, this plugin may cover Free CDN’s main feature too: you can rewrite http://www.yoursite.com into http://www.yoursite.com.nyud.net to make use of Coral CDN without having Free CDN installed.

Features

  • Multiple profiles are supported, allowing different contents to be treated differently
  • You can exclusively select the content types for each profile - currently supporting JS, CSS, images, inline background images, and <object>’s
  • Additional URL’s can be added as excludes
  • Debug mode gives you a good preview to make sure nothing goes wrong
  • Works normally with other plugins. Especially useful if run along with WP Super Cache
  • AJAX’ed admin section makes it quick and easy to adjust the settings

Installation and Documentation

  1. Download the plugin
  2. Extract into a folder
  3. Upload the entire to `wp-content/plugins/` directory of your WordPress installation
  4. Enable it via Plugins panel
  5. Head to Settings->CDN Rewrites and create the first profile.
  6. You’re ready to go!

FAQ and History

Head to plugin Codex page.

Download

There’s no demo yet - I don’t use commerical CDN personally and understandably :)
Download


Download the latest brain dumps and pass your JN0-350 as well as 650-195 certification exam in first attempt guaranteed.

  • wow this is big treat for us i used your previous plugin free cdn work great i hope even this work very well thank you so much

  • Thanks for the plugin. Found a minor bug though. If the theme doesn’t call wp_footer it doesn’t work.

  • Martin, it’s not a bug. Calling wp_footer or wp_header is required for almost every plugin, as the functions trigger the plugin actions.
    If a theme doesn’t call wp_footer or wp_header, then I can tell you it’s a sucking theme.

  • You can see this plug in work without actually having a CDN.
    Setup an A-Record for your domain like  images.domain.com
    Then use the plugin to rewrite all your images to be images.domain.com
    You can right click on one of the images and see the source URL.  Assuming you have a CDN, you could CNAME images.domain.com and get the same result
    - Mike Colburn

  • @phoenix.heart according to the codex: “This hook is theme-dependant which means that it is up to the author of each WordPress theme to include it. It may not be available on all themes, so you should take this into account when using it.”
    So strictly speaking the plugin should account for it.
    I think I might have discovered another few bugs.
    #1
    I suddenly wasn’t able to invoke the media upload dialog - clicking the icon it darkens the screen and then nothing happens. Disabling CDN and it works again.
    #2
    In the goTop() function in the admin.js file. t is undefined if clearTimeout() is called.

  • Martin, I agree with you on “strictly speaking”. But strictly speaking too, wp_header and wp_footer are mandatory, since almost all javascript, css includes, and a lot of other tasks are triggered via these two functions. So the themes should take them into account instead of them taking some specific themes IMHO.

    About the bugs:

    #1. I will certainly check again. However that’s not necessarily mean it’s a CDN Rewrites bug - sometimes it may be a plugin conflict.

    #2. This is A BUG! I forgot to declare t as global. Thank you!

    Cheers,

    An

  • #1, yeah maybe it is a conflict. I mocked around and I think if I removed the CDN jquery files the upload dialog would work again - so maybe there’s a jquery conflict with the WP jquery files !? But I guess if it works for you with WP 2.8.4 it’s more likely to be a plugin conflict…

  • An, did you delete my comment or it’s stuck in moderation?
    I filed a few tickets, please check the wordpress plugin page.

  • Strange enough Artem, I don’t see your comment in either approved, spam, or pending.
    I read your tickets on WP forum though, and wanted to says thanks :)

    You’re correct about including the plugin js and css on any admin page, it’s a bad habit as specified by Ozh some time ago. I will definitely keep this in mind for the next version.

    For jQuery, thing is my plugin(s) use live() which is only available from 1.3 when earlier WP versions (not sure with 2.9) only come with up to 1.2.x (please correct me if I’m wrong). If there is a way to force WordPress to use 1.3.2↑ I’ll much appreciate.

    For CDN Rewrites not working on your site, to admit I don’t have any clue yet. Help me with a bit more details will you?

  • An,
    I see your problem with .live(). Well, looks like 2.8 was the first one with 1.3, while 2.7 still had 1.2. You can easily check by looking at svn revisions: http://svn.automattic.com/wordpress/tags/2.8/wp-includes/js/jquery/jquery.js vs http://svn.automattic.com/wordpress/tags/2.7/wp-includes/js/jquery/jquery.js
    I think if you specify 2.8 as the min revision for your plugin, you should be able to then use wp_enqueue_script() and load the script correctly.
    For the rewrites, I haven’t played with your code yet. I will when I have some free time.
    Thanks,
    Artem

  • Great plugin, and works well with WordPress 3.0 beta1
    This is one of the few WordPress code tools that actually do understand how to correctly use multiple static assets!
    Well done!
    Peter Bowey

  • options page not work at all for 2.9.2 neither in latest chrome neither in latest firefox

  • js/admin.js line 126 you try to clear timeout with undefined id t, just cange it:
    else if (typeof t != ‘undefined’) { clearTimeout(t); }
    and functions in global namespace are evil, yo! :)

  • i just wandering how it is effective to setup a self hosted static CDN  like mycnd.myhost.com

  • Emonweb, I don’t understand your question.  Are you asking if this will really accelerate your pages?? More details… - Mike

  • Hi!
    I’ve installed your plugin on my site.
    Before you ask . . . I do have S3 set up, and have successfully served newly-uploaded images using the Amazon S3 for WordPress plugin.  It only uploads as new things are brought in, however.  And yes, I disabled it to test yours.
    Added a profile, set for images only. It appears to have no effect.  No upload dialog box (should there be one?).  Images are still served locally.
    I understood yours would upload the existing files and rewrite the URLs.  Did I misunderstand?  Or do something horribly wrong?
    Thanks!

  • Hi Mike, indeed you misunderstood. CDN Rewrites doesn’t upload the files, but instead rewrites your existing file links following your defined pattern. If you’re looking for a plugin that can upload files to a CDN, last time I checked W3 Total Cache has such a feature ;)

  • Mike D.

    Create a CNAME to S3 called  images.domain.com   or something like that.  Now using the Plugin, create an images profile.  The Plugin will rewrite the URL for all images to  images.domain.com  so now all the images will come from the S3.    But you still have to publish the content to S3 like you’ve been doing.  This plugin does not UPLOAD content anywhere, just rewrites URLs

    - Mike

  • Q-Zma is right from Apr. 15, 2010. Options page won’t save because of the missing check for t being a defined var. Can you fix please? Thanks!

  • Hi bro
    am using this plugin in me personal blog .. http://me.eadoking.com
    first I wanna thanks you very much :)
    but am having problem with mp3 file
    am hosting it to  me.eadoking.com/media/songs/mp3-file-name-example.mp3
     
    but it is not rewriten to me.eadoking.com.nyud.net … etc
    can you help me to do that …
    and the same with swf file
    thanks ..
    Eid Aldoukanji (EADOKING)

  • Found a very strange bug when enabling cdn-rewrites, all pages are displayed twice ….. yes twice… when cdn-rewrites is disabled the page is back to normal (displayed once).

  • Hi Mike D.
    I like your idea. Thanks for the spark!

    Dean

  • Great Plugins
    thanks a lot from berlin!
     
    cheers
    christian

  • Does this work with mulisite and subdomain blogs?
    WP3.1?

  • I installed the Channel theme, http://www.theme-junkie.com/themes/channel/ and the plugin stopped working, though it was working on Twenty Ten.  I think this is because of the issue you explained, wp_footer and wp_header hooks in theme.  How can I make this plugin working for Channel theme?

  • When this plugin is activated on WordPress 3.1, the button to add images to posts breaks.  Once the plugin is deactivated it immediately works fine.  Even with all profiles deactivated it breaks the add images button.

  • Hi, do you still support this plugin? Just asking because i was going to install it and see that it is not tested for wp 3.1.

    Is it working with a WP 3.1 Multi-sites?

    Thanks an advance for any answer :)

    Regards

  • Hey there, this would have been an awesome plugin except it doesnt work in WP 3.1. The admin UI is broken and you cant edit or delete profiles. Almost there, but this needs an update!

  • Why not you are updating the plugin??

  • Good working plugin, thanks for Sharing!

  • Works like a charm on my custom theme at my site!

    Props!

  • Thanks alot. That plugin its working like crazy. Save so much of my time. Props 
    Mr gratis Download 

  • Hi There,
    can u update your CDN.. to support compressed with .gz
    i found error if site use .gz
     
     
    Regard’s

  • There are so many WordPress-Plugins, that you must just be a fan of WP. Thanks for all suggestions. There’s plenty more!!!

You can follow any responses to this entry through the RSS 2.0 feed.

Trackbacks / Pingbacks