Javascript Src Path

Hello I’m having some trouble with the following code within my Index.html file:


This works when my Index.html file is in the same folder as clock.js. Both Index.html and clock.js are in my root folder.

But when my index.html is in these different directories clock.js does not load:


What can I put as the ‘SRC’ so that it will always look for clock.js in the root folder?

Thanks in advance!!


<script src=""></script>

Note the forward slash.

Use an relative path to the root of your site, for example:

If clock.js is on

Include :

<script language="JavaScript" src=""></script>

If it’s on your domain root directory:

<script language="JavaScript" src=""></script>

The common practice is to put scripts in a discrete folder, typically at the root of the site. So, if clock.js lived here:


then you could add this code to the top of any page in your site and it would just work:

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

Piece of cake!


This works:

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

The leading slash means the root directory of your site. Strictly speaking, language="Javascript" has been deprecated by type="text/javascript".

Capitalization of tags and attributes is also widely discouraged.


be careful it’s root of the domain.

P.S. and please use lowercase for attribute names.

If you have

<base href="" />

It’s will not load file right. Just delete it.

As you haven’t specified, I don’t know if you are working with flask (Python), but if you are, you have to put the JavaScript file in a directory called static. It should look something like this:


And then refer to the js file as following:

<script src="/static/clock.js"></script>

As your clock.js is in the root, put your code as this to call your javascript in the index.html found in the folders you mentioned.


This will call the clock.js which you put in the root of your web site.

Leave a Comment