18

Inspired by Dave Ward to host javascript files externally, I have several questions concerning the hosting of Javascript files externally:

Everybody knows that known libraries can be directly sources to, for free:

//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js
//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js

The scope of this question however focuses to hosting custom javascript files externally:

Q1. Is it possible to host private JavaScript files on a fast free public CDN?
Q2. Are there any speed penalties or is hosting on third party CDN practically always better?
Q3. Are there any safety risks involved in hosting custom JavaScript files externally?


Thanks to 13 people who have favorited this question, I am reopening this question! As of 2021, lightning fast websites (with all their JavaScript components) its more important than ever before to gather a collaborative understanding of objective ways to speed up page load. Untill this question is reopened, feel free to comment below your answer/suggestions to the three questions!

Sam
  • 15,254
  • 25
  • 90
  • 145
  • For those who use github, there is an easy way to convert your github link to jsdelivr. go to https://www.jsdelivr.com/github – The concise Aug 28 '23 at 08:23

5 Answers5

30

jsdelivr is a free, fast and reliable service to host your javascript files on a CDN.
The file should be on github repository first, then use the following format to use the CDN:-

https://cdn.jsdelivr.net/gh/user/repo@version/file

In the above format replace user with your username on github, repo with repository name and version with the version of your repository
You can use this CDN service for hosted anywhere like npmjs.com or even on your wordpress sites using their plugin.
Please visit the website for more information and to know how it works.

gamerboy
  • 403
  • 5
  • 8
  • 1
    +1 for jsdelivr. It has been consistency helping me in hosting assets in cdn. It accepts files from GitHub, Google Hosted Libraries, RawGit and unpkg. – yeaske Aug 19 '21 at 05:21
  • I've enjoyed jsDelivr for years, but it has been very flaky of late. 404 errors, inability to update the cache on changes, very slow updates on new GIT releases. Be cautious. Also make certain your repo is public. – Memetican Jul 15 '22 at 06:42
13

EDIT: as of 2021-07-10 this feature doesn't work at codepen anymore.


codepen.io allows you to host some js files without registration. Once you have an anonymous codepen saved the js part of it is available by just adding a .js at the end of your url.

Alex T
  • 1,296
  • 2
  • 17
  • 25
10

I'm using http://yourjavascript.com for 3 years and happy with their free service.

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36
user1866612
  • 165
  • 1
  • 7
4

You can use CoralCDN which is a free cdn. It is unlikely to be as fast as Google's but it's free!

Björn Lindqvist
  • 19,221
  • 20
  • 87
  • 122
1

If your script is hosted on Github or NPM, I would suggest jsDelivr. It even allows you to target a specific version, or minify your scripts.

Josiah Nunemaker
  • 781
  • 10
  • 20