Drupal CDN Integration

Drupal is a free, open-source CMS based on PHP. About 2.1% of the websites globally are powered by Drupal. Like other content management systems, it offers a wide range of modules that can be integrated into Drupal websites.

Slow Drupal website? KeyCDN can change that. Here’s why: KeyCDN will cache the static files of a Drupal website all around the world. In addition to optimizing a Drupal website, it’s essential to integrate a CDN for better performance. KeyCDN will cache the assets as long as specified in the HTTP headers defined by the origin server.

How does the Drupal CDN module work? The module will change the URL of static assets. The new URL will point to KeyCDN instead of the origin server. There is no redirection taking place, the URL will be rewritten to the KeyCDN domain. An example would be:

  • URL to the origin server: https://www.yourwebsite/drupalfolder/pic.jpg
  • New URL to KeyCDN: https://yourzone-ff99.kxcdn.com/drupalfolder/pic.jpg

Let’s get started with the Drupal CDN Integration

This tutorial shows how to complete a Drupal CDN integration with KeyCDN.

  1. Create a pull zone before you start with the Drupal CDN integration. A push zone would work as well but it’s not recommended here.
  2. Click on the menu item “Modules”,then click “Install New Module”.
  3. Go to Extend > Install new module > Install from a URL, enter the CDN Module URL: http://ftp.drupal.org/files/projects/cdn-8.x-3.0.zip (check the official Drupal CDN Project Page) and click “Install”.drupal install cdn module
  4. Go to the Extend page and under Web Services select both “CDN” and “CDN UI” then click Install.
    drupal cdn install
  5. Navigate to Configure > Web Services > CDN Integration. Set the CDN status to enabled and enter your CDN URL that you get from the KeyCDN dashboard, e.g. https://yourzone-ab12.kxcdn.com. You can also use your zonealias (e.g. http://cdn.yoursite.com). Save the changes.Drupal CDN Integration Configure ModuleThe setting “Far Future expiration” will define higher caching values for the assets (valid for KeyCDN, as well as the client’s browser). Longer cached assets will result in less request to the CDN and the origin server, this can further improve the loading time. Alternatively, if you want to define higher caching values for assets, we recommend to do so in the KeyCDN dashboard for this specific zone. Please note that content cached by KeyCDN can be purged anytime, but content cached by a browser cannot be purged.
  6. A red warning box appears. Click on “Aggregate and compress CSS files”. Within the Bandwidth Optimization box, check Aggregate and compress CSS files and Aggregate JavaScript files, then save the configuration.Drupal CDN Integration - Module Warning
  7. We always recommend to check the changes in the HTML code. Make sure the URLs have been rewritten properly.

That’s it. The Drupal CDN integration is completed. If there are any issues after the CDN integration, the KeyCDN support can be contacted anytime.

Drupal Cache Tags

Cache tag support was introduced with Drupal 8. Cache tags offer a convenient way to purge assets (also known as tag-based invalidation). It’s an alternative to purging by URL. The advantage of purging by tags is that several assets can have the same tag (vs. one asset can only have one URL).

The Drupal cache tags need to be added on the origin server. The Cache-Tag is a regular HTTP header returned by the origin server. It’s possible to add several tags separated by spaces as shown in the example below. KeyCDN POPs preserve the tags, which means the tags are also visible to end clients.

Cache-Tag: tag1 tag2 tag3

Once the cache tags are in place, it’s very easy to purge them. Execute the following steps:

  1. Go to the KeyCDN dashboard
  2. Navigate to Zones in the left menu
  3. Clicking the blue Manage button for a specific zone will show a drop down menu. Choose Purge by Tag.
  4. Enter at least one tag. If using several tags, separate them with a space and click on the purge button.CDN-purge-by-tags

In addition to purging tags via the dashboard, it can be purge the same way via the API.

The benefits of using KeyCDN with Drupal

Once KeyCDN is integrated into a Drupal site, there are lots of advantages to benefit from:

  • KeyCDN operates 24+ points of presence (POPs) around the world. The content will always be served from the closest location to the end users.
  • Real-time statistics can be monitored in the KeyCDN dashboard.
  • KeyCDN supports HTTP/2 for even faster content delivery. There’s no special configuration needed to take advantage of the new protocol.

KeyCDN also offers great tools and a up-to-date knowledge base. Here some useful pages:

3 Comments

Leave A Comment?