Amazon S3 is a sensible choice for storing your website’s assets in the cloud, but the benchmarks show that using a CDN is necessary to see any major performance gains.
If you’re reading this blog, you’re likely familiar with WP Offload S3, a plugin we offer that allows you to easily upload images and assets to Amazon S3. Storing your Assets on Amazon S3 is a great way to cut down on server space and keep your content in the cloud, but serving these assets from S3 isn’t always the best idea.
In this article we’ll be benchmarking three common ways to serve assets from your website – directly from the server, directly from Amazon S3, and from a CDN like Amazon Cloudfront.
About the Tests
Each test was run three times from the same location to ensure consistency, and the load time of all assets on that page was averaged together to get a reliable load impact.
Loading from the Server
This is the most common method of serving assets and how WordPress does it out of the box. The assets in these tests were loaded from a 2GB Linode VPS, running NGINX over HTTP/1.1.
This is fairly typical of a website that is serving assets directly from the server, with an average asset load time of 523ms. Of course, this number will increase the further away the physical server is located, since the assets are only being served from one location.
Loading from Amazon S3
This configuration is consistent with a basic configuration of the WP Offload S3 plugin. The images and CSS/JS files are all served directly from Amazon S3.
Yikes. Despite being served from Amazon’s high-availability servers, assets loaded from S3 took an average of 760ms, 45% slower than the assets loaded directly from the server.
There could be several reasons for this. The 2GB VPS likely has an advantage in terms of sheer processing power, and the S3 bucket is mainly designed for storage, leaving content delivery to a dedicated CDN like Amazon Cloudfront.
Loading from Amazon Cloudfront
Now let’s see if we can speed things up a bit. By creating a Cloudfront distribution that pulls from the S3 bucket, we can tell WP Offload S3 to load the assets through the CloudFront CDN. This should result in more consistently fast loading times even in different locations due to the distributed nature of CDNs.
That looks much better. With an average of 431ms per request, the assets were tested as 43% faster than loading directly from S3, and 11% faster than loading from the VPS server.
This goes to show that while offloading your images and assets to S3 can be a smart move to save space or backup your content, it shouldn’t be thought of as a massive performance boost. Depending on your location and proximity to the server, loading from S3 may actually hurt your performance more than help.
If you want your website to load quickly for a larger audience, a CDN is a no brainer, and will often be the fastest option. Have you ran any of your own benchmarks or use a CDN to serve your assets? Let us know in the comments below.