When does the "src" link in a script tag refer to a local file system resource (compared to non-local)?

If I have an HTML page with a script tag like this:

<SCRIPT SRC="./xxx.js"></SCRIPT>

Under what conditions could one access / get access ./xxx.jsfrom the local file system?

I understand that the URI / URL ./xxx.jsrefers to "a file with a name 'xxx.js'in the current directory", but when (under what conditions) does the "current directory" mean the current directory in the local file system on which the client / browser is running?

Is this the only situation where this would be the case when the HTML file containing this tag <script>was obtained from the local file system?

+4
source share
4 answers

I understand that the URI / URL "./xxx.js" refers to "a file named" xxx.js "in the current directory",

Rather, it means that it will refer to a file with a name xxx.jsrelative to the current file.

This means that it will look in the same directory from which the file containing the tag was downloaded <script>. If it is a local file system, it will load it from there. If it was sent from a web server, it will issue a new request to the web server for this file.

+5
source

URI , . , , html. , html - index.html, http://localhost/index.html. script , file://path/index.html, script

0

Oky, ..

src , - , , , -.

, javascript script src, javascript, script, .

0

When the src value is a path, it will be considered local and can be a relative path or an absolute path:

relative path examples

  • folder / subfolder / file.jpg
  • ../parent_folder/file.jpg

absolute path example

  • /root/folder/subfolder/file.jpg

When it is remote, the src value will be a URL, e.g. http://yourappsite.com/route/file.jpg

0
source

Source: https://habr.com/ru/post/1623101/


All Articles