1

How can I refer to a JavaScript file from GitHub in an HTML file? I have a JavaScript file. I need to upload it to GitHub and use it in my HTML files also I even edited the JavaScript file it will work in my HTML files with with the latest modification.

I tried to use

<script src="https://[myusername].github.io/[myrepository]/[filename].js"></script>
 script src="https://raw.githubusercontent.com/[myrepository]/[filename].js"></script>

it did not work then i tried the folowing:

<script src="https://cdn.jsdelivr.net/gh/<user>/<repo>/<filename>.js">

, which works, but doesn't load the latest modification of my JavaScript file.

starball
  • 20,030
  • 7
  • 43
  • 238
pro prog
  • 11
  • 1
  • The `raw` link must include the branch/commit/tag you are referencing. It should be something like `https://raw.githubusercontent.com/[myrepository]/[branch]/[filename].js`. – bfontaine Apr 05 '23 at 09:32

1 Answers1

0

It should be https://raw.githubusercontent.com/[username/organization-name]/[repository name]/[branch name]/[path to file].

cdn.jsdelivr.net is a CDN. CDNs usually implement some sort of caching. I wouldn't be surprised if you just need to wait for the caching period to pass to see your changes.

starball
  • 20,030
  • 7
  • 43
  • 238