jsdelivr-wordpress
The official WordPress plugin for jsDelivr Free Public CDN
How this works
-
We register a hook which looks for any JS/CSS files registered via WordPress API on every request. A list of all found files is stored in a database.
-
The list of files in DB is checked periodically and local files are paired with jsDelivr CDN URLs.
-
Just before rendering the page, we use
wp_register
/wp_deregister
functions to replace all assets which exists on the CDN with their CDN versions.
How matching works
- We use jsDelivr lookup API to check if a file exists on the CDN.
- If no, we check if the file is a plugin file and use jsDelivr plugin proxy endpoint.
- If no, we check if the file is a theme file and use jsDelivr theme proxy endpoint.
Development
You'll need php and node.js. Use npm install
and npm run composer:install
to install code style checkers.
Run npm test
before committing. See package.json
for a list of all available scripts.
Recommended: configure eslint, stylelint, and PHP Code Sniffer integrations in your IDE.