Icarus User Guide - CDN Providers
Choosing the right CDN providers can significantly reduce the page loading time of your viewers. Icarus lets you pick among several built-in CDN provider options for serving third-party libraries and asset files used by Icarus.
Built-in CDN providers
Currently, Icarus offers the following built-in CDN providers:
- CDNs for JavaScript Libraries
- cdnjs.com (
cdnjs) - jsDelivr (
jsdelivr) - UNPKG (
unpkg) - loli.net (
loli)
- cdnjs.com (
- CDNs for Web Fonts
- Google Fonts (
google) - loli.net (
loli) - font.im (
fontim) - ustc.edu.cn (
ustc)
- Google Fonts (
- FontAwesome Font Icon CDNs (both serve FontAwesome 6.0.0)
- FontAwesome (
fontawesome) - loli.net (
loli)
- FontAwesome (
The default CDN settings are:
1 | providers: |
Custom CDN providers
Additionally, you can also custom CDN providers via URL templates. The template formats for each type of CDN provider are listed below:
CDNs for JavaScript Libraries
1 | https://some.cdn.domain.name/${package}/${version}/${filename} |
You need to replace the actual package name, version of the package, and relative file path with ${package},
${version}, and ${filename} placeholders.
For example, a JavaScript library with the following URL:
1 | https://unpkg.com/d3@5.7.0/dist/d3.min.js |
can be generalized to this:
1 | https://unpkg.com/${package}@${version}/${filename} |
Some CDN providers may adopt different URL schemes.
For example, the clipboard library, which Icarus uses for the “copy” button of code blocks, has the URL like
this on CDN.js:
1 | https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js |
while has the following URL on UNPKG:
1 | https://unpkg.com/clipboard@2.0.11/dist/clipboard.min.js |
Therefore, you should be aware of the URL format of your custom CDN provider.
By default, Icarus will try to pass in the parameter using npm package name and relative file path
(e.g., clipboard@2.0.11/dist/clipboard.min.js).
This npm scheme is used by jsDelivr and UNPKG.
Otherwise, if you are using a CDN.js like provider, please prepend [cdnjs] to its URL template, and Icarus will
convert the package names and file paths to the ones used by CDN.js:
1 | [cdnjs]https://some.cdn.domain.name/${package}/${version}/${filename} |
CDNs for Web Fonts
You can pass in the URL of a Google Font mirror or compatible webfont CDN.
Icarus depends on the Ubuntu and Source Code Pro fonts for the default variant, and on the Oxanium and
JetBrains Mono fonts for the Cyberpunk variant, so make sure your CDN provides those.
The URL template should have two placeholders, type and fontname:
1 | https://some.google.font.mirror/${type}?family=${fontname} |
${type} is the path of the Google Fonts API, css or css2, and ${fontname} is the list of fonts.
Icarus requests the fonts with the newer css2 API, for example,
https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;600&family=Source+Code+Pro, so your mirror must
support it.
FontAwesome Font Icon CDNs
You can pass in the URL to a custom FontAwesome CDN. No placeholders are required. The provided custom CDN should at least have FontAwesome 6 icons as some of them are used in this theme. The built-in providers load FontAwesome 6.0.0.
1 | https://custom.fontawesome.mirror/some.stylesheet.css |
All of the above should be put in the providers section of the theme configurations:
1 | providers: |
Per-package CDN providers
Since Icarus 6.3.0, you can load some JavaScript libraries from a different CDN provider or URL than the one set
in cdn, for example, when a library is not available on your CDN provider.
Add the npm package names of these libraries to cdn_overrides, each with a built-in CDN provider name or a URL
template in the same format as cdn:
1 | providers: |
A URL without any of the ${package}, ${version}, and ${filename} placeholders, such as the one for
clipboard above, is used as is for every file of that package.
Therefore, only use it for packages that load a single file.
The following packages are loaded through these CDN settings:
- Icarus
jquery: used on every pageclipboard: the “copy” button of code blockshighlight.js: the code highlight theme stylesheets (two files withappearance: auto)pjax: the PJAX plugin
- Plugins and widgets (from hexo-component-inferno)
@waline/client: the Waline comment plugin and thewaline_pageviewplugin (several files)artalk,disqusjs, andgitalk(two files each),twikooandvaline: comment pluginsalgoliasearchandinstantsearch.js: the Algolia search pluginsocial-share.js: the Share.js share buttons (two files)lightgalleryandjustifiedGallery: the gallery plugin (two files each)katex(several files) andmathjax: the KaTeX and MathJax pluginscookieconsentandoutdatedbrowser: the cookie consent and outdated browser plugins (two files each)pace-js: the progress bar plugin
Other plugins load their scripts from your site or from the URLs of their own services, which the CDN settings do not change.
CDN helper functions
Three helper functions have been defined to help developers include third-party libraries easily with custom CDN support. You can check them out at ppoffice/hexo-component-inferno.
Icarus User Guide - CDN Providers
https://ppoffice.github.io/hexo-theme-icarus/Configuration/icarus-user-guide-cdn-providers/