npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hexo-cdn-jsdelivr

v0.0.9

Published

A hexo plugin to help you automatically use jsdelivr CDN for Github to speed up the loading of static resources like images.

Downloads

37

Readme

hexo-cdn-jsdelivr

English | 简体中文

Introduction

A hexo plugin to help you automatically use jsDelivr CDN for Github to speed up the loading of static resources like images.

If you want to use CDN for the static resources of your hexo website, jsDelivr provides an open-source CDN.

You may want to use this plugin and jsDelivr CDN when:

  • Speed up the loading of static resources of your Hexo website

  • Avoid inconsistent website access experience in different regions. For example, Github Pages is very slow to visit in China

  • Save the bandwidth of your server

Installation

$ npm install hexo-cdn-jsdelivr --save

You may come across some problems when using node 8.x version. We recommend that you use node >= 10.x version.

Options

You can configure this plugin in _config.yml.

jsdelivr_cdn:
  # If use_cdn is false, this plugin will not work
  use_cdn: true 

  # If deploy_when_generating is true, the assets repository will be pushed to github every time you generate the hexo project using 'hexo g' command. If this flag is set false, the repository will be pushed when deploying. You can manually push the assets repository to github when generating by using 'hexo g cdn' command.
  deploy_when_generating: true

  # cdn_url_prefix is the jsdelivr cdn url of your github repository(the assets repository for static assets rather than the hexo project deployment repository), it should be like: https://cdn.jsdelivr.net/gh/<username for github>/<assets repo name>/
  cdn_url_prefix: <the url of jsdelivr cdn for your github repository>

  # git_repo_url is the url of your new assets repository on github, it should be like [email protected]:<username>/<repo>.git
  git_repo_url: <git repository url>
  
  # you can use github token to push your assets repository. If you don't want to use a token, you can use a empty string '' or comment out this line. We do not recommand that you directly write your token in the _config.yml. We suggest that you read the token from the environment variable by setting token with a prefix '$'. e.g. '$GITHUB_TOKEN'. When you want to use token, you must use http(s) link of your repo. More information about github token can be found in https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line.
  token: <your github auth token, optional>

  # The path of an asset directory in asset_dirs should be the relative path to your hexo project directory, e.g. assets or source/assets or themes/<theme name>/assets. If you only want to use the cdn for the images in your posts, you can leave asset_dirs as empty
  asset_dirs:
    - [assets directory]
    - [another assets directory]

Usage

If you want to use this plugin, you should set thepost_asset_folder to true in _config.yml of your project. And you have to add the Options mentioned above to your _config.yml

You have to create a new repository in Github to store static assets. Set the repository link in options and this plugin will help you push static assets to the Github repository. Then the CDN link of your assets will be available in jsDelivr.

Images in Posts

As it is recommanded in Hexo documents, you can use {% asset_img slug [title] %} tag in your markdown post file to insert pictures in the posts.

Originally, setting post_asset_folder as true, you place the pictures in each folder for the posts. Now with hexo-cdn-jsdelivr, you don't have to move your pictures assets. This plugin will automatically push all your pictures of posts to the repository on Github and using the jsdelivr CDN link in the generated html pages.

Other Static Assets

Except for the images in posts, you can use this plugin to upload other static assets to CDN too! For example, you may have some .js or .css files on your site that you want to upload to the CDN.

There are several templates(which is Helper in hexo) you can use in to turn assets to CDN link.

<!-- You can use cdn_css(path) to replace css(path) in hexo -->
<%- cdn_css(path) %>

<!-- This is used to replace js(path) -->
<%- cdn_js(path) %>

<!-- This will return a url link which is the cdn link of the asset -->
<%- cdn_asset(path) %>

<!-- Examples -->
<%- cdn_css('style.css') %>
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/<username>/<repo>@latest/css/style.css"> -->

<%- cdn_js('test.js') %>
<!-- <script src="https://cdn.jsdelivr.net/gh/<username>/<repo>@latest/js/test.js"></script> -->

<img src="<%- cdn_asset('assets/test.png') %>"/>
<!-- <img src="https://cdn.jsdelivr.net/gh/<username>/<repo>@latest/assets/test.png"/>  -->

How it works

Thanks to jsDelivr. jsDelivr provides an open-source CDN for Github. So you can load all the asset files uploaded to Github from the CDN. You can know the jsDelivr CDN further by visiting their website.

In short, if the url of a file in your Github repo is like this: https://github.com/<username>/<repo>/blob/master/<filename>,you can also access the jsDelivr CDN url of it by https://cdn.jsdelivr.net/gh/<username>/<repo>/<filename>

hexo-cdn-jsdelivr works by copying the static assets files to .deploy_static_assets and then it will push this directory to your assets git repo on Github. Then you can load your assets through jsDelivr CDN.

This plugin will replace all the image links which come from asset_img tags in posts with the CDN link of each image.

Except for the assets in the _post directory and the asset_dirs set in the Options, the plugin will scan the public directory to find all the .js and .css files and upload them to github repo, in which way the css files generated by stylus can also be accessed by the CDN.

TODO List

  • [x] Add support for Github token
  • [ ] Add suport for markdown-style image inserting

Reset

$ rm -rf .deploy_static_assets

Reference

Some of the codes refer to hexo-deployer-git

License

MIT