use "jsdelivr" to host file

From the official features page of jsdelivr, we know that jsDelivr provides mirrors for npm, GitHub, WordPress plugins, and custom endpoints for several other projects with special requirements.

We will go through the Github and npm section.

There aremany kind of URLs on jsdelivr but as we only want to serve a css file for markdown preview in VSCode, so we only focus on the specific file way.

Github

The detail steps:

  • Create a new repository named cdn on Github.
  • Author the relevant css file named md.css which content can be found in serve a css file for markdown preview in VSCode.
  • Git Push to Github.
  • The cdn URL should be https://cdn.jsdelivr.net/gh/<github-username>/<repo-name>@<commit-hash>/css/md.css.

Note:

  • The file path is only specific for my case, change your path or name if necessary.
  • If you don’t use the <commit-hash> way, cdn will cache your css file which will result in confusion if you change you css and push again. There is no hook to purge the cache on cdn now. Except for this, I think this way is easier than npm.

npm

Instead of creating a repository on Github, you should publish a package on npmjs.com.

And in addition to authoring the css file, you should provide the entry point file index.js at the root directory of your package and import the css file.

import "css/md.css"

Then, the cdn URL should be https://cdn.jsdelivr.net/npm/@<package-name>/css/md.css

Note: Publishing updated packages will be rejected if you don’t change your package version, so it’s no cache problem mentioned above.

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
88
粉丝
82
喜欢
148
收藏
120
排名:66
访问:11.4 万
私信
所有博文
社区赞助商