I just changed my CSS image sprites to run from local to CloudFront and there's now a noticeable lag, even across pages and page reloads. Any ideas as to why this might be happening?
Moving images from localhost
to a server (in this case CloudFront) will always incur a speed penalty (relative to localhost
, certainly). This is because even with a great hosting service the browser has to send an http request via the internet to that server, to find out whether the document's been modified since it was previously cached, or not (not modified: HTTP response 304
).
Assuming that the document doesn't need to be downloaded again/re-cached that should be the end of the image-requests for the CSS (particularly if you're using css-sprites).
If the image-sprites have to be re-downloaded because the cache has expired, or the document's changed, then obviously the browser has to download the file again, via the internet and network. And this incurs a cost due to contention on your own network/intranet, between your house and your neighbours between home and cabinet and then whatever speed your ISP provides to you.
Whereas localhost
is the same machine, and (likely) has a response measured in the milliseconds. In contrast, accessing Amazon's CloudFront might only take a second or two, but that's still an order of magnitude (or more) greater.