WP Super Cache CDN Setup
November 22, 2024 · AI Conversations
For example:
– If your site URL is `https://example.com` and your CDN URL is `https://cdn.example.com`, setting the **Off-site URL** to `https://cdn.example.com` will ensure that static files are served from `https://cdn.example.com` instead of the main site.
### Steps to Configure:
1. **Enable CDN**: Check the box to enable the CDN functionality in WP Super Cache.
2. **Off-site URL**: Enter your CDN's base URL (e.g., `https://cdn.example.com`).
3. **Site URL**: By default, WP Super Cache replaces the base of your site's URL with the CDN URL. For instance, `https://example.com/wp-content/uploads` becomes `https://cdn.example.com/wp-content/uploads`.
4. **Include Directories**: Specify which directories should be served via the CDN (e.g., `wp-content/uploads`, `wp-includes`).
5. **Exclude Files**: Add any files or paths you don’t want to serve through the CDN.
6. Save your settings.
### Example Use Case:
If you’re using a CDN service like Cloudflare, BunnyCDN, or AWS CloudFront, you would:
– Configure the CDN to pull content from your server.
– Use the CDN's URL (e.g., `https://cdn.example.com`) as the "Off-site URL."
– WP Super Cache will rewrite asset URLs in your site's HTML to point to the CDN.
This helps improve performance by offloading static file delivery to the CDN's servers.
—
### Steps to Create and Configure `cdn.example.com`:
1. **Create a Subdomain:**
– Go to your domain registrar or hosting control panel.
– Create a subdomain named `cdn` (or any preferred name).
– Point the subdomain to your main site's server or the CDN provider's server, depending on the setup.
2. **Point the Subdomain to Your CDN (if applicable):**
– If you're using a CDN provider (e.g., Cloudflare, BunnyCDN, or AWS CloudFront):
– Add a CNAME record in your domain's DNS settings pointing `cdn.example.com` to the CDN's provided URL.
– Example: `cdn.example.com -> your-cdn-provider-url.com`
– If you're self-hosting (e.g., serving files directly from your server via the subdomain), ensure the subdomain points to the correct directory (e.g., `wp-content/uploads`).
3. **Configure the CDN:**
– On your CDN provider's dashboard, set up `cdn.example.com` as a custom hostname.
– Verify and enable HTTPS for the subdomain (most CDNs provide free SSL certificates via Let's Encrypt).
4. **Update WP Super Cache Settings:**
– In the WP Super Cache **Enable CDN** settings, use `https://cdn.example.com` as the **Off-site URL**.
– Ensure the **Include Directories** field includes paths like `wp-content/uploads` or other static asset directories.
5. **Test the Setup:**
– Clear your WordPress and browser cache.
– Visit your site and inspect the source code to confirm asset URLs are being rewritten to `cdn.example.com`.
—
### Do I Need a Subdomain?
Using a subdomain like `cdn.example.com` is not mandatory if:
– You're using a CDN provider that offers a generic URL (e.g., `https://example.cdnprovider.com`).
– You don’t need a custom subdomain.
However, a custom subdomain provides branding consistency and flexibility for DNS management.