Contao CDN Integration

Introduction

A Contao CDN integration can improve delivery of images, stylesheets, JavaScript, and other static files by serving them from your CDN Service Domain instead of directly from the origin server. This can reduce latency for visitors and offload static traffic from the origin.

This guide shows how to configure Contao's native Files URL and Assets URL settings. The procedure was tested on Contao Open Source CMS 5.3.51 and does not require an additional extension.

Before you start

  • This tutorial shows how to integrate a CDN service into a website. In this particular demo example we will use:
    • barsoom-cdn.cdnsun.org as the CDN Service Domain, and
    • https://barsoom.cdnsun.org as the website URL (i.e. barsoom.cdnsun.org is the Origin Domain).
  • Please visit the Services/How-To section to obtain your CDN Service Domain.
  • Before you take any steps please back up your files and database.
  • To integrate a CDN service on https:// website the CDN service must have SSL enabled.
  • If your website embeds custom fonts then please first enable CORS for them.
  • Before you take any steps please make sure that your CDN Service Domain is ready-to-use here.

Create CDN Static service

Please refer to Creating a CDN Static service for more details.

How to enable CDN in Contao

  1. Sign in to the Contao back end and select Pages from the left navigation.
  2. Locate the website root that serves the public site. Click its pencil icon to edit the website-root settings.
    Contao Pages screen with the Barsoom website root
  3. Expand Global settings. Enter your CDN Service Domain in both Files URL and Assets URL. Contao uses Files URL for resources from the files directory and Assets URL for resources from the assets directory. The screenshot uses barsoom-cdn.cdnsun.org for both fields.
    Contao Global settings with Files URL and Assets URL set to the CDN Service Domain
  4. Click Save to apply the website-root settings. Open the public site and confirm that the frontend remains styled normally and static assets load from the CDN Service Domain.
    Styled Contao frontend after configuring the CDN Service Domain

Verify & Troubleshoot

  • View HTML source code of your web pages to verify that you are using CDN, you should see source attribute of your images, CSS, JavaScript, etc. beginning with your CDN Service Domain.
    Frontend HTML proof that static assets are loaded from the CDN Service Domain
  • Don't see your CDN Service Domain in the source code of your web pages? If your website is using any cache plug-in/mechanism then you might want to clear/flush its cache.
  • Having trouble with custom fonts? Please refer to Using custom fonts with CDN - setting CORS for more details.
  • Still having trouble? Check your CDN URLs using our content check tool or please refer to Debugging a CDN service for more hints.

Contact Us

 _    _    __   __    _____   
| \  / ||  \ \\/ //  |__  //  
|  \/  ||   \ ` //     / //   
| .  . ||    | ||     / //__  
|_|\/|_||    |_||    /_____|| 
`-`  `-`     `-`'    `-----`