Chapter 8. How-to Guides

Use a Content Delivery Network (CDN)

A content delivery network keeps copies of your images, CSS and JavaScript on servers around the world, so each visitor downloads them from somewhere close by. JCH Optimize works with any "pull" CDN: one that fetches files from your site the first time they are requested and gives you a CDN address to load them from, such as cdn.example.com.

Load your static files from a CDN
  • A CDN account with a pull zone (sometimes called a distribution or resource) whose origin is your site's address.

  • The CDN address for that zone. Many CDNs let you use your own subdomain, such as cdn.example.com, set up with a CNAME record in your domain's DNS; follow your CDN's instructions.

  1. Check the CDN address works: open https://cdn.example.com/ in your browser. You should see your site's home page (possibly without styling). If you get an error, fix the CDN setup before continuing.

  2. On the settings page, open the CDN tab.

  3. Set Enable to Yes.

  4. In Domain 1, enter the CDN address without https://, for example cdn.example.com.

  5. Leave CDN scheme on https if your site uses HTTPS.

  6. In Static Files 1, choose the kinds of files to load from the CDN. All of them is a good start.

  7. Save, and check your pages. Right-click an image, choose Inspect, and check that its address now starts with your CDN address.

    Figure 8.5. The CDN settings
    The CDN tab with the feature enabled, a CDN domain entered and static file types selected.

    Joomla

    The CDN tab with the feature enabled, a CDN domain entered and static file types selected.

    WordPress


Pro In Pro, you can add file types that aren't in the list with Custom extensions 1, and spread files across up to three CDN addresses with Domain 2 and Domain 3.

Caution

If fonts or icons disappear after enabling the CDN, your CDN isn't sending the header that allows fonts to be used by another domain (Access-Control-Allow-Origin). Enable it in your CDN's settings (often called CORS), or untick fonts in Static Files.