9

I am able to load my javascript file on the local machine. But on github pages, it is not working.

I have included the file in index.html as

<script src="script.js" type="text/JavaScript"/>

The website is https://abhikulshrestha22.github.io./

The code is at https://github.com/abhikulshrestha22/abhikulshrestha22.github.io

Any help would be appreciated. Thanks in advance.

Edit 1 I tried to add the following code in my javascript file to check if its working, but it is not working on github page and working locally.

$(document).ready(function(){
    alert("hi");}
Abhishek Kulshrestha
  • 1,373
  • 4
  • 17
  • 31

3 Answers3

13

Try this

<script src="script.js" type="text/javascript"></script>

Use closing script tag.

For more check this answer.

Durga
  • 15,263
  • 2
  • 28
  • 52
  • it works!! but could u please tell why was it working on the local machine then? – Abhishek Kulshrestha Jul 16 '18 at 08:04
  • @AbhishekKulshrestha check this [post](https://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work) and [this](https://stackoverflow.com/a/348818/3551786), they have mentioned everything. – Durga Jul 16 '18 at 08:21
3

<script> tags need a closing tag even if it loads an external script.

You forgot it, so it tries to run </body></html> instead.

enter image description here

Sebastian Speitel
  • 7,166
  • 2
  • 19
  • 38
-1

I think the issue is with wrong spelling.

Try this:

<script src="script.js" type="text/javascript"/>

I would advise you to move js files in a js directory on the root, following some best practices.

Vikas Yadav
  • 3,094
  • 2
  • 20
  • 21