A content delivery network (CDN) keeps copies of your images, stylesheets, scripts and fonts on servers around the world, so visitors download them from a location near them. Powered Cache connects your site to a CDN by rewriting the addresses of these files in your pages to your CDN hostname. Your HTML pages keep coming from your own server.
Available in: Powered Cache (free)
Where to find it: Powered Cache → CDN
Requires: an account with a CDN provider that offers a pull zone (also called an origin pull or pull CDN).
How CDN integration works #
With a pull CDN, you do not upload anything. The first time a visitor requests a file from the CDN, the CDN fetches it from your site and keeps a copy. Powered Cache only changes the addresses in your pages, for example:
https://example.com/wp-content/uploads/photo.jpg
→ https://cdn.example.com/wp-content/uploads/photo.jpg
Addresses are rewritten when they point to your site’s domain or are root-relative paths such as /wp-content/themes/theme/style.css, and when they end in one of these file types:
- Images:
jpg,jpeg,gif,png,bmp,ico,webp,avif,svg - CSS and JavaScript:
css,js - Fonts:
woff2,woff,ttf,otf - Other:
pdf,mp3,mp4
Version query strings such as ?ver=6.8 are kept. Minified and combined files created by file optimization are served from the CDN too. Pages are not rewritten in the admin area, for previews, block editor requests, or requests other than GET.
Set up a CDN #
- In your CDN provider’s dashboard, create a pull zone and set its origin to your site address, for example
https://example.com. - Note the hostname the provider gives you. If you want a hostname on your own domain, such as
cdn.example.com, add it in the provider’s dashboard, create the DNS record they ask for, and make sure HTTPS works for it. - Test the CDN before you switch: open one of your images with the CDN hostname, for example
https://cdn.example.com/wp-content/uploads/photo.jpg. It must show the image. - In WordPress, go to Powered Cache → CDN and turn on CDN Delivery (Rewrite asset URLs).
- Under CDN Hostnames, enter the hostname and leave Applies to on All files.
- Click Save Settings, then clear the cache so cached pages use the new addresses.
- Open your site in a private window and check in the developer tools that images, CSS and JavaScript load from the CDN hostname. Check that fonts and icons still display (see CORS for fonts).
Settings #
CDN Delivery #
Turns address rewriting on. Default: off. Nothing is rewritten until at least one hostname is set.
CDN Hostnames #
One row per CDN hostname. Enter only the hostname, for example cdn.example.com. If you paste a full URL, only its hostname is used. Click Add Hostname for another row and Remove to delete one.
Applies to (CDN zone) #
Each hostname has a scope that decides which files it serves:
| Applies to | Files |
|---|---|
| All files | Every supported file type. Also the fallback for types that have no hostname of their own. |
| Images | Image files. |
| JavaScript | .js files. |
| CSS | .css files. |
Most sites need one hostname set to All files. Use separate scopes when your provider gives you different hostnames, for example an image CDN for images. Fonts, PDF, MP3 and MP4 files only use an All files hostname, so add one if you want those on the CDN. If you add several hostnames with the same scope, Powered Cache picks one of them at random for each file.
Changed in 4.0: Hostnames and the file types they serve are now managed together, one row per hostname with an Applies to choice. Your existing hostname and zone pairs are kept.
CDN Excluded Files #
Files that should stay on your own server. Default: empty. Enter one rule per line. Each rule is compared with the file address as it appears in the page, which is a full URL or a path.
- Plain text matches when the address contains it:
/wp-content/uploads/private/,custom-script.js. - Wildcards:
*matches any characters:/wp-content/plugins/*/assets/*.js,*.pdf. - Regular expressions also work. A line that is not a valid regular expression is matched as plain text.
Exclude files that must come from your domain, for example scripts that check where they were loaded from, or files that a security rule protects.
New in 4.0: CDN Excluded Files supports
*wildcards.
CORS for fonts #
Browsers only use a font from another domain when the response allows it with an Access-Control-Allow-Origin header (CORS). Your CDN hostname counts as another domain. Without the header, text falls back to a system font and icon fonts show empty squares, and the browser console shows a CORS error.
A pull CDN usually passes on the headers your server sends, so add the header on your server:
Apache and LiteSpeed #
When CDN Delivery is on and Automatically configure .htaccess is on (Powered Cache → Advanced), Powered Cache adds these rules to .htaccess for you. They allow fonts from any site, and images when the browser asks for them with CORS:
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
<FilesMatch "\.(avifs?|bmp|cur|gif|ico|jpe?g|jxl|a?png|svgz?|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
If you manage .htaccess yourself, add the same rules above the WordPress block. The server needs the mod_headers module. See Server Configuration.
Nginx #
Nginx does not read .htaccess. Add a block like this to your site’s server block (or ask your host to add it), then reload Nginx:
location ~* \.(eot|otf|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin *;
}
After adding the header, purge the font files in your CDN’s dashboard, because the CDN may still have copies without it. You can also set the CORS header in the CDN itself if your provider offers that option. See Server Configuration for the rest of the Nginx setup.
Things to know #
- Purging: Powered Cache does not clear a generic CDN. When you replace a file but keep its name, purge it in your CDN’s dashboard. For Cloudflare, see Cloudflare Integration.
- Proxy CDNs that sit in front of your whole site, such as Cloudflare with your domain’s DNS, already serve your files from their network. You do not need CDN Delivery for them.
- Files loaded by JavaScript after the page is built, and files on other domains, are not rewritten.
Troubleshooting #
Files still load from my domain #
Clear the page cache, then check that a hostname is set for that file type or for All files, and that the file is not matched by CDN Excluded Files.
The site looks broken after turning on the CDN #
Open one of the failing file addresses directly. A 404 or SSL error means the pull zone or its hostname is not set up correctly in your provider’s dashboard. Missing fonts or icons point to CORS. Turn off CDN Delivery and clear the cache to go back while you fix it.
For developers #
The file types can be changed with powered_cache_cdn_extensions and powered_cache_cdn_image_extensions, the hostnames with powered_cache_cdn_addresses, and rewriting can be turned off with powered_cache_cdn_disable. The automatic CORS rules can be turned off with powered_cache_htaccess_add_cors. See the Hooks Reference.