Paul Warnick Paul Warnick - 3 months ago 8x
HTML Question

In HTML, what is the difference between accessing JavaScript code locally and accessing it from a webpage?

I'm working with Bootstrap and I'm trying to use the bootstrap.min.js script found here.

In my code, if I use the following script tag everything works as expected:

<script src=""></script>

Whereas if I save the code found at the above link into a file called bootstrap.min.js and run the following code, the script no longer works.

Note: I'm saving the bootstrap file one directory above where my HTML is saved.

<script src="../bootstrap.min.js"></script>

If the first option works what am I doing wrong (or not doing) to make the second not work?

I'm new to web development but from what I understand, when you use the
tags in HTML, all that happens is the script at the location specified in
src=" "
is run. Where in this case, both options seemingly point to the same code.


In answer to your title, I have to delve into practices and ways of work.

CDN's (using a script from a link) isn't generally a good idea for development, as you don't have that script when offline and anything relying on that will fall over. However, it saves space (as you don't store the script), and it is quite manageable as well (with regards to directories and building doesn't modify the paths etc.). In development, local files are a good idea. In production, however, it is a good idea to either use minified JS, or CDN's, for storage saving.

In answer to your question body, you have to get the path right (including the file name). ..\ goes to the parent directory to start off with, while .\ is the current directory. Also, the <script> reference tag has to be above all usages as the page is loaded from top to bottom. Take those tips and see what the issue is.