Sitemap
Javarevisited

A humble place to learn Java and Programming better.

How to host your repository JS/CSS on Open Source CDN “jsDelivr”

--

A couple of years back i was searching for an completely free & opensource cdn service but i couldn’t find any at that point of time & I ended up using Netlify (Another alternative was Hostry).

But then this idea struck “what if there was a cdn service which could use Github as CDN”. Most developers use Github as their code repository, keeping all their UI assets like fonts , js , css , images etc. Fast forward today, my quest ended on CDN delivery service called as .

jsDelivr open source cdn over github assets

jsDelivr CDN over GitHub Assets

jsDelivr does exactly what many of us need, provides a opensource cdn over github assets. Let look into it in detail.

Here’s how it works.

  1. jsDelivr CDN service’s base URL is http://cdn.jsdelivr.net/gh/{username}/{repo}/, where you replace {username} with the GitHub username and {repo} with the repository name for the project.
  2. Append that URL with the path to the file you want to access in the project. For example, consider my sample project , the JavaScript file(dummy-js-file.js) is located in the /dist directory.
<html>
...
...
<script src="http://cdn.jsdelivr.net/gh/root0109/github-cdn/dist/dummy-js-file.js"></script>
...
...
</html>

You can also take advantage of semantic versioning by adding @{version-number} to the repository name. You can target major, minor, and patch releases as desired.

Load the latest version

<script src="http://cdn.jsdelivr.net/gh/root0109/github-cdn/dist/dummy-js-file.js"></script>

Load with Major Version only

<script src="http://cdn.jsdelivr.net/gh/root0109/github-cdn@2/dist/dummy-js-file.js"></script>

Load with Major.Minor Version

<script src="http://cdn.jsdelivr.net/gh/root0109/github-cdn@2.1/dist/dummy-js-file.js"></script>

Load Exact version

<script src="http://cdn.jsdelivr.net/gh/root0109/github-cdn@1.0.0/dist/dummy-js-file.js"></script>

Load minified version

Add “.min” to any JS/CSS file to get a minified version — if one doesn’t exist, it will be automatically generated for you.

Questions ? Suggestions ? Comments ?

What’s next? Follow me on Medium to be the first to read my stories.

Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Vaibhav Singh
Vaibhav Singh

Written by Vaibhav Singh

I am a #TechnologyEnthusiast #Coder #JavaProgrammer #Blogger () #Dreamer. In my free time I love to #Cook, #ShareStories & #VolunteerForPoor.

Responses (6)