Using CDNJS from Wordpress

Hi all,

I have been searching for an answer for quite some time without luck. Apologies if this has been answered already. I have a client with a WordPress site that relies on a number of common JS libraries and CSS.

I want to change them to use the Cloudflare CDN rather than the copies hosted in our server. I was wondering if there is away to configure this in Cloudflare (using injection) or if I have to manually change the address within WordPress to point to the CDN.

The client has a “Pro” subscription for Cloudflare.

Thanks in advance.

I’m pretty sure there’s not automated way to do it. There are so many JS sources that may or may not exist in CDNJS.

What’s wrong with hosting them on your server? Hopefully up to date, and they’ll be cached plus you won’t need an additional DNS lookup.

Thanks for the response, that certainly seems to be the case. I wasn’t looking for it to replace all, just wondered if there was anything like this.

If you’re using nginx you can use nginx substitution filter to replace html contents of a page with the cdn served version too

i.e. example in wordpress of serving gravatar images locally from

  sub_filter '' '';
  sub_filter_last_modified on;
  sub_filter_once off;

  location /avatar {

Ha! That somehow seems much easier than:

1 Like

This option is faster since you are doing it at the edge, but for things the first is easier to implement, especially of the server is close to one of the remote origins (same data center) which won’t impact things a lot expect for bandwidth usage.

Yeah nginx sub filter is easier for end users to implement - shouldn’t make much difference if you have css/js cached with long TTL at Cloudflare edge too.

Yeah there’s many ways to do it :slight_smile:

1 Like

Thanks for all the great responses.

This topic was automatically closed after 30 days. New replies are no longer allowed.