drewbrolik / Responsive-Img

Responsive Img is a jQuery plugin that changes an image's src attribute based on its container's width.
207 stars 36 forks source link

Will this work with a CDN? #1

Open adambiggs opened 11 years ago

adambiggs commented 11 years ago

Haven't had a chance to try this yet, but just wondering:

If an image has already been generated by the PHP script, will it load properly from a CDN without hitting the origin server for each request?

drewbrolik commented 11 years ago

That's a good question. I hadn't thought of that.

I'm guessing there could be come complications there, but I'd have to try it out to really know. I'm only somewhat familiar with the ins and outs of CDNs.

In theory, if the image gets served from a CDN, the PHP script should attempt to put a new image only on the server it directly comes from... but in the real world, I'm not sure if it would try to put it on the origin server or on the actual server the CDN routed the request to (especially if the CDN changes the url).

I'd like to think that there would be a way to easily modify the plugin to get that to work (if it doesn't work), because I tried to write it with versatility in mind, assuming that there will be other questions like this, too.

If you're using a CDN on a project and are interested in trying it out, I'm willing to try to help you fix issues and get it running.

adambiggs commented 11 years ago

We're on a tight schedule ATM, but when there's time I'll definitely try this out with CloudFront.

I love the idea of processing images when-needed. Right now we're generating about 4-5 different image sizes at the time of upload, some of which might never even be used... It can get pretty slow if the user batch-uploads 20-30 hi-res images.

This also has the nice bonus of never needing to run a batch process on all our existing images if we choose to add a new size.

Plus, now that S3 supports CORS, we might even be able to upload new images directly to S3 without any load on our servers!

Nice work, great idea!

drewbrolik commented 11 years ago

Thanks, that's all good to hear. I had the same thinking about images for our CMS, as we used to create multiple images on upload as well.

So far, it's been working great.