1

I am trying to understand what is the difference between when I load files/script from the server in my HTML like this:

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

And like this:

<script src = "http://example.com/js/file.js"></script>

Assuming that example.com is my own domain, how will this differ the loading of the file? I mean that will it use cookies to connect to the site or just look for the directory?

I think the second one connects to the server using a cookie, and the first one just retrieves file/script from the folder, making the second method network consuming.

halfer
  • 19,824
  • 17
  • 99
  • 186
Gourav
  • 2,746
  • 5
  • 28
  • 45
  • 2
    Possible duplicate of [relative url and absolute url difference](https://stackoverflow.com/questions/3591899/relative-url-and-absolute-url-difference) – Randy Casburn Jan 25 '19 at 17:32
  • No sir, see my edited question – Gourav Jan 25 '19 at 17:36
  • That question describes the difference between relative and absolute urls but my question how will using the both effect the loading of the scripts! – Gourav Jan 25 '19 at 17:37
  • Possible duplicate of [Absolute vs relative URLs](https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls) – Heretic Monkey Jan 25 '19 at 17:40
  • I did. Please read the answers to that question. They are explicit in detailing how they affect server performance. See also [Https Performance: absolute vs relative urls](https://stackoverflow.com/q/31629497/215552) – Heretic Monkey Jan 25 '19 at 17:41
  • I asked that how it will effect the loading of the web page? – Gourav Jan 25 '19 at 17:42
  • ...which is a function of how those files are loaded **from the server**. – Heretic Monkey Jan 25 '19 at 17:43
  • Will it use cookies or not? That's the question! – Gourav Jan 25 '19 at 17:43
  • 2
    The [edit] your question to make *that* your question. The only sentence in your post with a question mark is "Assuming that example.com is my own domain, how will this differ the loading of the file?" Also, please learn some humility and start rereading your question to see how several people have interpreted it. It might be due to how you've written it, not due to how others have read it. That's all the time I'm willing to invest in this question. Good luck. – Heretic Monkey Jan 25 '19 at 17:48
  • Thanks I will edit this question! – Gourav Jan 25 '19 at 17:48
  • You should read this: [What is a URL?](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_is_a_URL), but perhaps you really start here and investigate how HTTP, URLs and Cookies work in general: [Complete beginners start here!](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web) – Randy Casburn Jan 25 '19 at 18:23
  • On a Meta note, [my post here on confident questions](https://meta.stackoverflow.com/questions/366264/how-can-we-encourage-new-authors-to-ask-confident-questions) would be a good read for you. I've removed pleading from several of your questions, and you are continuing to grovel in an unseemly fashion. Reading this article will benefit you greatly: if you address volunteers calmly and succinctly, using the technical writing we prefer here, your questions may get a better reception. – halfer Jan 25 '19 at 22:30
  • Sorry sir, I'll have a look at them! – Gourav Jan 26 '19 at 04:19

1 Answers1

0
<script src = "/js/file.js"></script>

load file.js on your local server

<script src = "http://example.com/js/file.js"></script>

load file.js on internet at http://example.com

  • 1
    Sir this answer doesn't fit my needs. Please see my edited question. – Gourav Jan 25 '19 at 17:38
  • the relative URL does not load the file from your local server - it loads the file from a file location that is relative to the HTML file that contains the ` – Randy Casburn Jan 25 '19 at 18:14