Serve Static Files From a CDN
Rewrites same-site static file URLs to an origin-pull CDN hostname. Independent of Cloudflare: you can run both, one, or neither. Cloudflare can keep caching eligible HTML while the browser fetches the selected files from the CDN hostname.
Off by default. Configure it on the CDN tab.
GT Performance does not upload files or configure a provider account. It only changes URLs in the HTML, so the CDN must be able to fetch every original WordPress path from your site.
Configure
- Create an origin-pull (pull zone) resource at your CDN provider that fetches from this WordPress site.
- Turn on Enable CDN URL rewriting.
- Enter the CDN URL: the HTTPS hostname, or hostname plus path, your provider gave you (for example
https://cdn.example.com). A port is kept if you include one. Anything that is not a validhttps://URL is discarded on save. - Under Files served by the CDN, tick the exact extensions the CDN should serve.
Rewriting needs both a CDN URL and at least one extension. With either missing, nothing changes.
File types
| Group | Extensions | On by default |
|---|---|---|
| Images | jpg, jpeg, png, gif, webp, avif, svg, ico | Yes |
| Styles and scripts | css, js, mjs | Yes |
| Fonts | woff, woff2, ttf, otf, eot | Yes |
| Video and audio | mp4, webm, mp3, ogg, wav | No |
| Downloads | pdf, zip | No |
Unselected types keep their original WordPress URLs.
What gets rewritten
A URL is rewritten only when all of these hold:
- It is an
httporhttpsURL whose host matches the host ofhome_url(),site_url(), orcontent_url(), or it is root-relative (/wp-content/…) or protocol-relative (//example.com/…). - Its path ends in a selected extension.
- It is not already on the CDN base, so running the rewrite twice changes nothing.
The CDN URL (including any path you entered) replaces the scheme and host. The original path, query string, and fragment are kept: https://example.com/wp-content/uploads/a.jpg?v=2 becomes https://cdn.example.com/wp-content/uploads/a.jpg?v=2.
Places it looks:
src,href,poster,data-src,data-lazy-src,data-original, anddata-bgattributessrcsetanddata-srcset, candidate by candidateurl(…)inside inlinestyleattributes and inside<style>elements
Because href is included, selecting pdf or zip also moves ordinary download links to the CDN.
Left untouched:
- Third-party URLs, and
data:,blob:,mailto:,tel:, andjavascript:URLs - HTML routes and any path without a selected extension
- REST, AJAX, cron, feed, and
robots.txtresponses, and wp-admin - URLs inside external stylesheet files
- SVG
<use>references, because browsers refuse to resolve a sprite across origins and every icon would disappear - Any element with an
integrityattribute, because Subresource Integrity plus a cross-origin URL without CORS makes the browser drop the resource
When a font preload (<link rel="preload" as="font">) is moved to the CDN, crossorigin="anonymous" is added so the browser can use the preloaded file instead of fetching it twice.
Rewriting uses WordPress’s HTML tag processor, so markup it does not change (inline SVG, non-Latin text) is left byte-for-byte as it was. Safe Mode turns rewriting off along with every other HTML transformation.
How it interacts with the page cache
The rewrite runs twice, safely:
- Inside the page-cache pipeline, so cached HTML already contains CDN URLs and a cache hit serves them with no extra work.
- As the outermost output buffer, started before the page-cache capture, so pages that bypass the origin cache still get CDN URLs.
Because the rewrite is idempotent, the second pass finds nothing left to change.
Purging
Changing any CDN setting purges the origin page cache (and, through it, the Cloudflare zone when Cloudflare is connected), so no cached page keeps the old URLs. GT Performance never purges the separate CDN. When you replace a file without changing its URL, purge it through your CDN provider.
Unused CSS
The unused-CSS engine reads stylesheets from this site’s own host and from the CDN hostname, so a stylesheet already rewritten to the CDN is still analyzed. The gt_performance_css_allowed_hosts filter can add other hosts you own. See CSS Optimization and Hooks Reference.
Choosing extensions
The defaults cover images, styles, scripts, and fonts. If you are unsure of the CDN’s configuration, start with images only:
- Add fonts once the CDN sends
Access-Control-Allow-Origin. A CDN that drops it breaks web fonts specifically, and that failure looks like a font problem rather than a CDN problem. - Add
css,js, andmjsonce you have confirmed the CDN serves them with correct MIME types.