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:
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).
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/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.
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.
15 thoughts on “xiaodu-jsdelivr: WordPress Plugin To Scan and Serve Static Files From jsDelivr CDN”
我有个站点，安装了 woocommerce 及相关的插件，他们的 JS 文件无法被替换，出现在了报错记录里。
我是通过 WP官方插件市场 找到的。
Glad you are enjoying it!
据我观察，WordPress 定时任务用 WP-Cron 好像是比较通用的方式。CPU 高占用具体是什么原因呢？
开发者文档里有把 WP-Cron 用服务器定时任务触发的文档，可以先尝试一下。如果这个插件单独做一套定时触发机制，好像就有点复杂，暂时还没有计划……
是的，等待 scan 成功之后看一下网站前台源代码，静态文件应该大部分被替换成 jsdelivr 的链接了。
Many plugins which uses jsdelivr as CDN has stopped their development. Hoping that you continue to develop the plugin.
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.
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
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