Absolute file path for java script

I have a small javascript library written by me. I want to reference it in my web application, but it does not work.

<script src='file:\\C:\Path\To\Script\Script.js'></script> 

Is it possible to reference javascript when everything you know is an absolute path?

+7
source share
2 answers

URL file: requires 3 forward slashes, and paths also need forward slashes:

 <script src='file:///C:/Path/To/Script/Script.js'></script> 

This will only work if you download the script in an html file to your disk loaded into your browser.

+12
source

Although I'm a Mac guy, my (limited) understanding of Windows security is that it has restrictions on running Javascript files โ€œlocallyโ€. It would be best to copy the file to the web application directory structure and reference it through a relative path.

This will not only provide greater reliability, but also one more thing to keep in mind when deploying to a web server or something similar. If the JS file is outside the folder structure of the application, when deploying to a remote server, you still have to include it.

0
source

All Articles