When you should avoid using a CDN on your website

CDNs are used to provide a fast, reliable resource delivery for websites with global audiences.

CDNs are everywhere on the internet now. Your favorite streaming services like Netflix and Hulu use CDNs, Shopify and Squarespace sites use a CDN by default, even many “normal”, non-tech giant sites use CDNs to deliver their web content. That brings up the question, should your website be using a CDN? The answer depends on many factors specific to your website. We’ll break everything down by section so you can skim the headlines and quickly see what applies to your specific situation and decide if a CDN would benefit your website.

What is a CDN?

We’ll start with a little background information on what a CDN is and why they matter. Feel free to skip this section if you’re already familiar with the basics.

A content delivery network (CDN) is a group of geographically distributed servers that work together to provide fast delivery and high availability of internet content such as website pages, javascript files, images, videos, etc. Fast delivery and high availability is achieved by distributing (duplicating) this internet content across multiple servers that are spread across many physical locations. A user can then communicate with the “closest” server to get their content faster.

In a single server distribution (what your website has without a CDN), all users communicate with the same web server (called the origin server). In a CDN distribution scheme, users communicate with the CDN server that is “closest” to them. Refer to the graphic below for a visual example.

(Image Source) Single server distribution (left) vs CDN scheme of distribution (right)

When should I avoid using a CDN?

1. When most of your website visitors are in the same geographic area

A CDN aims to distribute your website files across geographically spread CDN servers to ensure that website visitors far away from your website’s origin server can still load your website quickly. You lose out on the main benefit of a CDN if most of your website traffic is local, which is generally true for smaller, local businesses.

For small businesses whose website traffic consists largely of local visitors, your best bet is to choose a great website hosting provider with servers in your area. Then, for further speed improvements you could use a preloading plugin. Padeo is a free plugin that predicts the next page that a user will likely visit. It then preloads that page’s content in the background, so the next page load is extremely short because the bulk of the work is already done.

2. When a CDN provider has no servers close to your website visitors

This one is less likely to be an issue depending on where you and your website visitors are located, but it’s worth mentioning. The locations where your CDN provider has servers is very important and varies per provider. As a general rule, you want to select a CDN provider that has servers in the locations where most of your audience is, otherwise you’re not taking advantage of the main benefit of CDNs — reducing the distance between your visitors and your website content.

3. When your website has low traffic (applies to origin pull model CDNs)

If your website has low traffic, it’s possible that a CDN could actually slow down your website. This applies to CDNs that use the “pull” model for caching files from your origin server, rather than the “push” model. With a pull CDN, the CDN is responsible for pulling the right content from your origin server to deliver to visitors.

How Origin Pull CDNs work: You leave your content on the origin server (your original website server), and rewrite all the URLs on your website to point to the CDN. When content is requested, the CDN server goes to the origin server, pullsthe content, and then serves it to the visitor. The CDN then caches that content until a certain expiration time. Next time that resource is requested, the CDN already has it saved in the cache and can skip contacting the origin server — saving time and making things load more quickly.

The problem with pull CDNs is that files drop out of the CDN cache after not being requested for a set amount of time or after they expire. This is usually not an issue, unless you have low traffic on your site.

When a file not in the CDN server cache is requested:

  1. The client (user) request goes to the CDN server.
  2. The CDN server recognizes that the file is not cached (called a cache-miss).
  3. The CDN server “pulls” the file from your website’s origin server, returns it to the client, and caches it for next time. This extra step of going from CDN server to origin server increases page load time.

When a file in the CDN server cache is requested:

  1. The client (user) request goes to the CDN server.
  2. The CDN server recognizes the file is cached and has not expired, so it returns the file to the client. This step potentially saves time by skipping the origin server.
  3. The files in cache are not necessarily shared across every CDN server (this varies per CDN provider), so a file can be in the cache on one CDN server and outside the cache on another CDN server. If your website doesn’t get enough traffic to keep your files “hot” (in cache) on all the CDN’s locations, then the CDN could potentially be serving your visitors cache-misses very often, potentially making your site slower than not using a CDN at all.

For websites with low traffic, a CDN likely isn’t the most cost effective choice for decreasing load times on your website. Instead, try out the free Padeo website plugin. The free version is perfect for sites with low traffic because you get all the benefits and features for your first 500 website visits every month. And it’s completely free, so there’s zero cost unless you upgrade your plan yourself.

4. When your website has a lot of dynamic content

There are two types of website content: Static and Dynamic.

Static content is any file that is the same every time it is delivered to users. Dynamic content changes based on factors specific to the user such as location, device type, time of day, etc. This means that a dynamic page looks different for every user, and can change as users interact with it.

How caching usually works with static content

The usual web caching process is that a cache will save a copy of a static file (an image, a script, etc.) when the content is served, so that it’s closer to the user and delivered more quickly the next time it is requested. Browsers and content delivery networks (CDNs) can cache static content for a set time period and serve it to users as long as the content continues to be requested. This is possible because static content does not change over time; the same file can be delivered to users over and over.

The downside of dynamic web pages is that the same HTML page cannot be cached and served to multiple users because each user’s HTML page is different. Server-side scripts generate these dynamic page’s HTML files in response to real-time user events (like interacting with the page, logging in, etc).

Because dynamic content is generated by server-side scripts, they are usually served from your website’s origin server, instead of from a CDN server’s cache. If your website has many pages with dynamic content (that cannot be cached and served by CDN servers), then you’ll miss out on the potential speed increases that a CDN offers. Again, this is because dynamic content usually has to be served from your origin server.

Some CDNs can cache dynamic content, but it’s complicated:

Some CDNs are able to cache dynamic content, the process is just much more complex. A CDN can cache dynamic content by running those server-side scripts that generate the dynamic content in a CDN cache instead of in the origin server. So the dynamic content is generated without the origin server and then can be served from the CDN cache.

For example, Cloudflare supports dynamic content caching through the use of Cloudflare Workers, which are essentially serverless JavaScript functions that run on Cloudflare’s CDN servers and can respond to user events and inputs to generate dynamic content. This added functionality adds a lot of complexity, and they’re not exactly “plug and play”. You’ll need developer-level knowledge to write and maintain the serverless code that tells the service how to respond to user events and inputs. This extra cost and maintenance may be worth it if you have the budget and resources. If you’re looking for a faster website and don’t want to bother figuring out if a CDN would work for you, consider Padeo’s predictive preloading service.

5. If your website has many webpages with private or sensitive information

Last one, let’s talk about the Cache-Control header. This HTTP header holds instructions for caching HTTP requests and responses. A server can set the header to Cache-Control : private to indicate that a response may only be stored by a browser’s cache. This means intermediary agents (like CDN servers) cannot cache responses with this directive.

Certain industries (healthcare, legal) have websites where Cache-Control : private is set for the majority of pages for privacy reasons. Padeo can predictively preload pages with sensitive or private information that CDNs and similar services cannot cache because Padeo preloads the page into the client’s browser cache, meaning data never leaves the website visitor’s device.

It can be difficult to figure out if some of these situations apply to your specific website, especially if you’re not a web developer yourself. If you’re looking for a solution that improves loading times and just works, check out intelligent preloading from Padeo.

Leave a Reply

Your email address will not be published. Required fields are marked *