R
R
rinaz222020-06-23 23:44:10
Browsers
rinaz22, 2020-06-23 23:44:10

How does the browser know where to download site files from?

Hello. When we open the site, a request is made to the server and a response is received. There are styles on the page, the path of which is written like this: css/style.css
How does the browser know that these styles need to be loaded from this particular site? Does it get it from some http header or what? If so, is it possible to send another domain (host) in response, i.e. to make the browser load styles from another domain?
Please do not write that you just need to change the path to the style or the like.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2020-06-23
@Stalker_RED

If the styles are written like this:

<link rel="stylesheet" href="http://example.com/css/style.css">

that is, the address is specified in its entirety, then the browser will request it.
If written like this:
<link rel="stylesheet" href="//example.com/css/style.css">

that is, without specifying the protocol, the browser will substitute the same protocol as the current page (usually http or https).
If it is written like this: <link rel="stylesheet" href="/css/style.css">
that is, only the path from the root of the site (pay attention to the slash at the beginning), then the browser will substitute the current protocol and domain.
If they are written like this: <link rel="stylesheet" href="css/style.css">
that is, the path is NOT from the root of the site, then the browser will substitute the address of the current PAGE, and on the page with the address
https://mysite.com/hello/world.htmlan attempt will be made to connect styles like this:
https://mysite.com/hello/style.cssand this will most likely lead to an error.
But the first three methods are quite working, and the third is most often used. It's more comfortable and weighs less :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question