3

Is there a way i can define my script tag to use absolute path instead of relative path so that my JavaScript files are loaded from a network location?

This is what i have tried:

<script src="file:\\\MyDFSDirectory\Test\TestApp\Scripts\jquery-1.7.1.js"></script>

This does not work. in FF, i get the error Security Error: Content at http://localhost/Test/Test.html may not load or link to file:\\\MyDFSDirectory\Test\TestApp\Scripts\jquery-1.7.1.js

In IE, I dont see the file being downloaded. In Network Tab (IE Dev Toolbar), it shows Received 0 B. If i take the URL and paste it in the File Explorer, it opens the JS file.

What am i missing here?

4
  • Try to host js file locally also. Using different protocols might (and should) throw security warnings.
    – fed.pavlo
    Commented Jul 28, 2014 at 14:36
  • If i wanted to host them locally, i would not have put them on network drive. :)
    – Asdfg
    Commented Jul 28, 2014 at 14:50
  • @Asdfg, but I'm not sure what you're expecting. Web browsers serve files via the protocols defined. You could "spoof" the file by using an HTTP handler at a specific URL (e.g. .../jquery), which then on the web server went and retrieved the file from the UNC path. That's the only real option you have. Consider the constraints you're working in. Commented Jul 28, 2014 at 15:00
  • @Asdfg than you will be restricted by browser security.
    – fed.pavlo
    Commented Jul 28, 2014 at 15:51

1 Answer 1

4

You are indeed running up against the security model of the browsers. The only way around this is to run a web server locally and serve up the files that way.

6
  • That is an option but i am trying to avoid it.
    – Asdfg
    Commented Jul 28, 2014 at 14:46
  • It's so easy to run a quick web server these days. Python, PHP, Node... They all have quick command-line web servers that you can just fire up with minimal pain.
    – Matt
    Commented Jul 28, 2014 at 15:02
  • Problem is not to get the web server up and running. Its the replication that has to happen to all the regions. Adding one more component to the maintenance is what i am trying to avoid.
    – Asdfg
    Commented Jul 28, 2014 at 15:31
  • I'm also assuming that you're not just trying to load jQuery here, and that you're merely using that as an example. But, using a CDN for loading jQuery (or any other file) would obviate the need to run a web server as well.
    – Matt
    Commented Jul 28, 2014 at 15:33
  • @Asdfg some browsers allow to avoid that, e.g: in IE - you can manage security levels - but this will work only for individual use, most users prefer to have default settings.
    – fed.pavlo
    Commented Jul 28, 2014 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.