rewriting URLs for using a CDN for your Wordpress blog

A lot has been written about Wordpress tuning. Unfortunately utilizing CDNs with Wordpress is despite a few plugins still fiddly and requires modifications to themes, links and the such. Yet even a lot of plugins don’t correctly link to their JS files, resulting plugins such as My-CDN not being able to rewrite all links.
Therefore I have written a plugin to hook a rewriter into PHPs ob_start(). Without going further into technical detail, it lets you use a CDN for your Wordpress blog within minutes.
Download the “OSSDL CDN off-linker” here: Wordpress Plugin page.
That’s how it works:
Unzip the plugin into your wp-content/plugins folder.
It will rewrite at any links which point into wp-content or wp-includes your blog URL with an URL of your choice. That could be e.g. a second domain for static files only, Amazon S3 or CludFront storage, Nginx caching statics or even a dedicated CDN. By that you can decrease load on the server hosting your blog. Take a look at this blog’s HTML code.
How to start:
The easiest start is subscribing at a CDN which supports origin pull. Then you can just configure your blog’s URL as the origin and let the service provider pull all static files request per request.
Or, you can upload your CSS, JS, images and the such by a tool, e.g. to Amazon S3 and let it there be served by CloudFront. This article describes how, and this one how you can directly upload your attachments.
For a Nginx proxy please see also my article to be found here.
The plugin is compatible with WP Super Cache plus and can be deactivated and deleted without leaving any artifacts.















Follow me on Twitter
[...] Continued here: rewriting URLs for using a CDN for your Wordpress blog [...]
I always enjoy learning what other people think about Amazon Web Services and how they use them. Check out my very own tool CloudBerry Explorer that helps to
manage S3 on Windows . It is a freeware. http://cloudberrylab.com/
[...] Following is my bash script for copying Wordpress blog files, such as downloads, images, attachments in general to CloudFront. Written it with efficiency in mind it will actually synchronize files thus sparing you massive uploads and lets you use CloudFront as CDN. [...]
The plugin can be found on Wordpress plugin page:
http://wordpress.org/extend/plugins/ossdl-cdn-off-linker/
[...] use a CDN so I can’t recommend one but OSSDL CDN Off Linker might be worth a shot. This post on it mentions Supercache plus, a fork of this [...]
[...] OSSDL CDN off-linker [...]
Has anyone tested this with NextGen Gallery? I am getting to the point were I am seriously looking at going CDN / W3 Cache.
Blakjakk, I use it myself with NextGen Gallery, see the category photography. You neither need to tweak the scripts nor do anything else special. It works just out-of-the-box.
Hi,
First off, love your plugin – what an easy CDN solution!
I am however having an issue – I have items in my template that are in the root directory of the site, and your plugin is rewriting those URLs as well. Also, the browser is not recognizing the favico.ico file after installing the plugin.
If you go here for example:
http://screenrant.com/scream-4-set-pics-ghostface-voice-benk-67331/
Scroll down to the comment box, there should be a gravatar image there, but with the plugin activated it rewrites this:
http://screenrant.com/sr-gravatar.jpg
to this:
http://cdn.screenrant.com/
Thanks,
Vic
Vic, I will need the raw HTML of one of your blog’s pages twice: one with the plugin being on, and off. See my email.
Update 2010-07-09: new version 1.1.1 of the plugin
Hi Vic,
Great plugin. A joy to use and far better than W3 Total Cache, despite the hype about that plugin.
I do have a question: I’m using multisites on WP 3 and I now have the plugin set to load wp-includes and wp-content off another web site running on the same (my dedicated) server. That works well for the main site, but not for my subdomains, since the images, etc for those sub-sites reside in the blog.dir folder.
Is there a way around this? It’s not too bad if there isn’t –the main site should be really fast; the rest is of lesser importance, but it would be nice if it worked on all sub-sites.
Thanks for any advice you care to give!
-Erik
Forget what I asked…. Boy, I must be sleepwalking. I forgot to fill in the correct URL for the CDN!
Sorry…
Erik, nice to hear the plugin works for you. Did filling in the CDN resolve your issue with the mutliple sites? Is this Wordpress-MU?
Hi Vic,
It’s actually WordPress 3.0.1 with multiple sites. It was my own stupid mistake: I just clicked the Save button instead of first filling in the URL where the assets now reside. Of course that didn’t work.
One word of advice to your users though: if you combine the OSSDL CDN plugin with AutoOptimize –as I do– then I have bad experiences with turning on the CDN URLs for JavaScript, images, etc, on anything BUT the main site.
It does work on your main site, but (in my case at least) it will not work when you turn those on in the other sites. You should, however, fill in the CDN URL in ALL sites in the OSSDL plugin.