Technical insights: boosting Drupal site speed with the StackPath CDN
Pete Graylish

Adaptive’s new StackPath module for Drupal 7 is bringing great performance gains for our clients’ sites. It provides an intelligent CDN and caching solution for websites, delivering lightning-fast page load times whilst also improving site security and reducing the load on (and, therefore, cost of) the origin server hosting the website.

Here Adaptive's CTO, Pete Graylish, explains the background to the project and how our new StackPath (SP//) module works.

Over the past few months, we’ve updated our hosting and WebOps setup and migrated many of the sites we host and support over to Drupal-optimised hosting platform, Pantheon. A significant part of this work has been in finding efficiency and performance gains for these sites, as well as the cost savings these improvements will bring.

One of the most effective methods of improving the performance of a site is to place it behind a Content Delivery Network (CDN). Although Pantheon has its own CDN, we wanted to be able to seamlessly enhance this with extra capabilities such as Web Application Firewalls (WAF). To this end we looked at all the major CDN offerings in the marketplace: AWS CloudFront, Cloudflare, Fastly and many others. Our final choice was StackPath, for its broad global reach, range of technical features, including provision for both URL and tag-based caching, excellent support and sensible pricing model.

Drupal x Stackpath simplied architecture diagram

Caching content in StackPath is straightforward, simply requiring some DNS changes to route traffic through the CDN and the setting up of the caching rules. The complexity comes with ensuring stale content is removed from the cache as it gets updated on the site. For Drupal 8 sites, this is taken care of via the existing Purge suite of modules. However, for Drupal 7, no StackPath integration module existed.

The solution

To ensure we’re making the best use of StackPath’s capabilities, Adaptive has developed a module which works alongside the d8cache contrib module, which adds the same tag-based caching functionality to Drupal 7 that comes natively with Drupal 8.

The module integrates with StackPath’s API to send custom cache purge requests, both for URLs and tags. Whenever a content update is made, the module is triggered and works out what needs to be removed from the CDN cache, authenticates with API and then sends the request. See the screenshots at the end of this post for examples of the settings available in the module to provide these levels of control.

Sidebar: URL vs tag-based caching


Website content can be cached via its URL or by content tags. While StackPath offers both URL and tag-based caching, the latter offers far greater control over purging of cached content / page elements when updates are made to the site.

URL caching is simple and straightforward: whatever is delivered by the web server on a given path is cached, eg

Tag-based caching is much more granular in that both content and individual page components such as menus, views, header and footers have unique tags to identify them and when they are used in a page. When any content or component is updated the system uses these tags to identify all instances where they appear and remove those pages from the cache. This allows indirect uses of content (eg news articles listed in a view) to be identified and purged when an article is created or amended.


The challenges

Managing cached content across multiple CDN layers is unusual, but it does add an extra level of resilience to the site’s hosting setup and allows us to quickly and seamlessly activate additional services such as a WAF. The biggest challenge we faced was in identifying and finding solutions to exceptions where one or more layers of the caching system would not be purged correctly after a content update.

Purging of Pantheon’s CDN is normally handled by the Pantheon Advanced Page Cache module. Although the module is a ‘black box’ with no configuration options nor logging output to keep track of what it’s doing, in most cases we found this to operate as expected. However, there were scenarios where non-standard custom content functionality would fail to identify the correct tags to be purged from the cache.

To address these situations we created additional functionality in our module to define cache tags that should always be ignored, always sent with every purge requests, URLs and recursive page paths that should always be sent, and the option to send these purges to Patheon’s CDN as well.

There is also a useful admin function for admins to send user-defined URL or path purges – always useful when testing new setups.

Finally, all purge request activity and errors can be logged to Drupal’s watchdog, providing invaluable debugging information for the tech supporting the site.

In conclusion

Adaptive’s StackPath integration module allows the full power of the CDN to be deployed, greatly improving site load times and responsiveness without compromising on the site owner’s ability to have new content available the moment it gets published.

To find out more about increasing the performance of your website via Pantheon hosting and StackPath CDN, contact us for further details

Pictured below - examples of the cache-control settings available in the module developed  by Adaptive:

Drupal Stackpath Module Settings Screen 1

Drupal Stackpath Module Settings Screen 2​​​​​​​​​​​​​​