JS file storage location?

I’m very new to JS. I understand that when you want to use JS in a page, its file reference gets inserted just above the closing ‘body’ tag with script tags: <script src"main.js">. My website is shared hosting by Godaddy.

But where is this ‘main.js’ file created and stored? Thanks.

It’s wherever the file is being served from. With what you’ve given and default setup, the file will be in the same directory as your index.html file

Does that mean it’s within the html of the code of the page? Or is it separate from the page but in the file system of the website on the Godaddy server. If it’s in the file system of the website on the Godaddy server then each web page will have a separate JS file?

Hi there Engine44,

personally I would put in a folder named “scripts” and
place it in the same location as you HTML file.

It would then be called thus…

<script src="scripts/main.js"></script>

I would then place that code just before the closing
body tag </body>



There was a recent discussion on the correct placement of scripts, which might be helpful. It starts here:

1 Like

Yes, body tag. Would it be with the html file or within the html file? Either way it would sit on the Godaddy server.

Hi there Engine44,

you basic document should look like this…

<html lang="en">

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<title>untitled document</title>


<script src="scripts/main.js"></script>


Yes, my mistake. Thanks.

No mistake. smile I just thought you might find it useful.

Ok, the JS file is only referenced in the html file. I’m trying to clarify where it is actually sitting. Thanks.

You can place the file wherever you want, but I would agree with @coothead that it generally makes sense to have a directory (folder) called “scripts” and keep all JavaScript files in that. Then you reference it as shown:

<script src="scripts/main.js"></script>

If you simply place it in the same directory as your HTML file, then you would reference it as:

<script src="main.js"></script>

I prefer having an,/assets/ directory with lots of sub-directories such as CSS, IMG, SVG, JS, etc.

The idea is to keep the root directory as clean as possible and make it easier to group everything.

1 Like

If I use this approach: then all the JS files would be in the ‘scripts’ folder and that folder would sit on the Godaddy server in the files location of the website.

1 Like


Yes, that’s correct.

Very good. Thanks

Hi there Engine44,

check out the attachment, which contains a complete
working example…

Engine44.zip (1.7 KB)


Thanks very much.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.