xiaodu-jsdelivr: WordPress Plugin To Scan and Serve Static Files From jsDelivr CDN

I created a plugin called “xiaodu-jsdelivr”, which automatically scan and replace references to WordPress static files, including plugins and themes that can be found in the official repository, with their canonical jsDelivr CDN addresses.

The plugin has been uploaded to the official WordPress plugin category. You can search for “xiaodu-jsdelivr” in the plugin installer, or download the ZIP archive here to install.

How it works

I downloaded and tested some of the existing WordPress plugins with jsDelivr replacing feature, and noticed that most of them employ a passive approach, which is to wait for visitors to request some static files, and then search the file hash against jsDelivr’s lookup API.

My plugin instead uses a more proactive approach. It starts by scanning static files directly from the WordPress installation directory, instead of waiting for visitors’ requests. To do this, I used the official WP-Cron scheduler to perform scans in the background at fixed intervals.

Then it will calculate local file hashes and compare them with known URL patterns (both WordPress itself and its official plugins and themes are supported), and matched URLs will be recorded and later used to replace local file references when they are requested. This is more reliable than just using the lookup API, because it can match against files that have never been visited by anyone, thus cannot be discovered simply by looking up hashes.

Here is a screenshot of what wp-content references can transform into with the plugin enabled:

Demo of plugin

Note the four different kinds of successful scan results shown in the screenshot above: Base WordPress files (line #32 – #35), an official plugin (#36), an official theme (#38 and #42) and custom files that the fallback hash lookup successfully found (#37).

Why jsDelivr

There are a handful of popular and reliable static file CDNs available. I think other plugin developers and I probably chose jsDelivr for the same reasons:

  • It has native WordPress support, namely https://cdn.jsdelivr.net/wp/plugins/ and https://cdn.jsdelivr.net/wp/themes/ that point to official plugin and theme SVN repositories. Other static CDNs mostly just load from GitHub and/or NPM.
  • It is more reliable in Mainland China, thanks to the QUANTIL (ChinaNetCenter / WangSu) nodes it uses for the Chinese visitors. Their overall visitor performance is better than their alternatives. The alternatives usually perform pretty bad in PRC.

Future development

The latest stable version will always be published to the WordPress plugin category. The plugin is GPLv2 (or later) licensed, and the first version (1.0) comes with full functionality and all the features mentioned above.

Future development will be carried out in the public GitHub repository.

20 thoughts on “xiaodu-jsdelivr: WordPress Plugin To Scan and Serve Static Files From jsDelivr CDN

  1. 官方插件停止更新了,希望作者大大能把这个持续更新下去。
    遇到了点问题,一个站点扫描正常,另一个扫描总是超时(两个站点都是一个服务器上的)
    我有个站点,安装了 woocommerce 及相关的插件,他们的 JS 文件无法被替换,出现在了报错记录里。

    1. 感谢支持!居然真的有人在用这个插件,想问下是通过什么途径找到的呢……

      有几个文件替换不了、导致每次扫描都超时的问题,可以试试更新下插件版本(1.2 以上),加了失败记录功能,后续扫描会自动跳过之前失败的文件。

  2. 面向中国客户采用wordpress的境外网站非常需要jsDelivr,你的插件解决了静态资源自动同步CDN的问题,希望能继续更新下去。
    如果已经有了一些wp-cron任务,很可能引发高占用cpu,这个插件可否不采用wp-cron,而是用服务器定时任务。

    1. 是的,等待 scan 成功之后看一下网站前台源代码,静态文件应该大部分被替换成 jsdelivr 的链接了。

  3. Dude,
    Many plugins which uses jsdelivr as CDN has stopped their development. Hoping that you continue to develop the plugin.
    Best Wishes,
    Binil

    1. Hi Binil,

      That’s one of the reasons why I started it. The other is that most of them don’t work the same way mine does, so their successful replace rates are not as good.

      I believe the current version already has a complete feature set. But I will continue to add minor tweaks and fix compatibility issues, since my blog is also using it.

      Thanks!

  4. 谢谢作者,我一直在寻找可以扫描并替换为jsDelivr的方法,您的插件非常好用!
    1、安装
    2、等待扫描👉自动替换
    没有比这个插件更简单的使用jsDelivr的方法了!感谢您作者!希望您可以继续开发下去,再次感谢!

  5. We are currently testing your plugin with our new retail online shop .. our team saw huge improvement in loading speed .. thank you so much
    we hope that you continue supporting this plugin and test it with the latest WordPress versions

  6. Dont know how i get here since browsing learning about optimizing my js with jsdelivr. After reading your blogpost and wordpress repository details i’ve installed your plugin and BOOOMMM.. All the speed test result is showing the green ones showing grade A in term of speed.. I just want to say: GREAT PLUGIN and MANY THANKS! Love form Indonesia

    1. 这个消息通常是没有尝试访问 API,是否确认打开了 API 开关并且填写了 key?(其实好久没看过它的代码了,印象不深了…)

回复 杨景文 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注