Setting Up a CDN
xSpeed Cache can rewrite the URLs of your static files so they load from a CDN instead of your own server. This page explains how to turn that on and control which files it applies to.
What this does
A CDN (content delivery network) stores copies of your static files on servers around the world. When xSpeed Cache’s CDN feature is on, it changes the URLs of images, fonts, CSS, JavaScript, and similar files in your pages so visitors download them from the CDN hostname you provide.
xSpeed Cache works with a pull-zone CDN. That means the CDN fetches files from your site on demand the first time they are requested, then keeps a copy. xSpeed Cache never uploads anything to the CDN. It only changes the URLs in your HTML.
Only files on your own domain are rewritten. Links to other sites are left alone.
Why use it
Serving static files from a CDN takes load off your server and can shorten the distance between your files and your visitors. Pages that include many images, scripts, or fonts often load faster as a result.
Requirements
- A pull-zone CDN account (for example BunnyCDN, KeyCDN, or your own) set up to fetch files from your site.
- The CDN hostname you were given, such as
cdn.example.com.
Note: You configure the pull zone in your CDN provider’s dashboard, not in xSpeed Cache. xSpeed Cache only needs the hostname once the zone points at your site.
How to set it up
- In your CDN provider’s dashboard, create a pull zone that fetches from your site’s URL, and note the hostname it gives you.
- In WordPress, open the xSpeed Cache settings and go to the CDN module.
- Turn on Enable CDN.
- In CDN URL, enter your CDN hostname, for example
cdn.example.com. - Save your settings.
- Load a page on the front end of your site and check that images and scripts now point to your CDN hostname.
Tip: You can enter the CDN URL with or without
https://and a trailing slash. xSpeed Cache strips those automatically and stores just the hostname.
Settings explained
| Setting | What it does | Default |
|---|---|---|
| Enable CDN | Rewrites static file URLs to the CDN hostname below | Off |
| CDN URL | The CDN hostname that files are served from | Empty |
| Included File Extensions | The file types that get rewritten | See list below |
| Excluded Patterns | URL paths that should stay on your own server | Empty |
Enable CDN. Turns the feature on. When this is off, or when CDN URL is empty, xSpeed Cache leaves all URLs unchanged. Default: off.
CDN URL. The hostname your files are served from, such as cdn.example.com. Your CDN must be a pull zone configured to fetch from this site. Default: empty.
Included File Extensions. Only file URLs ending in one of these extensions are rewritten. The default list covers images, fonts, CSS, JavaScript, and common media:
jpg, jpeg, png, gif, webp, avif, svg, ico, woff, woff2, ttf, otf, eot, css, js, mp4, webm, mp3, ogg
Change this only if you want to add or remove a file type. Default: the list above.
Excluded Patterns. Glob patterns matched against the URL path. Any URL whose path matches a pattern stays on your own server instead of going to the CDN. You can use the * wildcard. Examples:
/wp-admin/**.pdf/private/*
Default: empty.
Best practices
- Test on the front end after enabling. Confirm that file URLs now use your CDN hostname and that images and styles still load.
- Keep the included extensions list focused on static files. Files that change often or contain private data are better left on your own server using an excluded pattern.
- If a CDN URL stops working, you can turn off Enable CDN to send all files back to your own server while you investigate.
Troubleshooting
Files still load from my own domain. Check that Enable CDN is on and that CDN URL is filled in. xSpeed Cache leaves URLs unchanged if either is missing. Also confirm the file’s extension is in the Included File Extensions list, since only listed types are rewritten.
A specific file should not use the CDN. Add a pattern that matches its path to Excluded Patterns, for example *.pdf or /private/*.
Broken or doubled CDN hostnames. Running another plugin that also rewrites URLs to a CDN can conflict with xSpeed Cache. xSpeed Cache refuses to run its CDN rewriting alongside the CDN Enabler plugin for this reason. Use only one CDN rewriting tool at a time.
FAQ
Does xSpeed Cache upload my files to the CDN? No. xSpeed Cache only changes the URLs in your HTML. Your pull-zone CDN fetches each file from your site the first time it is needed.
Will links to other websites be changed? No. Only files served from your own domain are rewritten.
Related
- Cloudflare Integration
- How to Enable Page Cache
- Purging the Cache