JJohn
JJohn

Reputation: 75

Help understanding the setup of a CDN?

Here's a few questions I cannot find in search:

When adding CDN services to your website, do you still maintain/create local dynamic files on your origin server and point the CDN to that location, set a http rule, and have them upload it automatically if they aren't hosting it yet?

Let's say I have an avatar upload form on my origin server and after a cropping function, do I set the save image to the local directory or to the CDN?

The other question I have is if you save files locally first and wait for the CDN to pull them, how do you code for the page to know the difference? Do you use some thing like

// $filename = 'images/image.jpg';
function static_file($filename) {
    $cdnfilepath = 'http://cdndomain.com/';
    if (fopen($cdnfilepath.$filename, "r")) {
        return $cdnfilepath.$filename;
    } else {
        return $filename;
    }
}

Or, do you just PUT every dynamically created file that you would like the CDN to host directly to the CDN?

If anyone knows a good tutorial on this that would helpful. Sorry if any of this has been covered but I having been searching with no clear answers...

Upvotes: 1

Views: 438

Answers (1)

fire
fire

Reputation: 21531

Sometimes there's no straight-forward way of uploading directly to your CDN.

For example with AWS you have to PUT the file, which means it still has to be uploaded to your server temporarily. What I do is upload the files to a temp directory then have a cron script run that PUT's the files onto AWS, so as not to cause the upload process to take any longer for the end-user.

Upvotes: 1

Related Questions