SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    739
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question How does web servers serve Media with relative path?

    Hello

    I have been trying to find an answer to this for long but no dice so finally posting it here hoping someone can help me understand the concept.

    Consider the following HTML code:

    <!--index.html-->
    Code:
    <html>
    <head>
    <title>Welcome</title>
    </head>
    <body>
    <img src="images/banner.png" />
    </body>
    </html>
    The Scenario:
    Suppose I have an apache web server running on a machine and the web root folder has the above index.html as well as the banner.png image sitting under the "images" directory under web root. A user requests the page from a remote location using the server's domain
    phantom007.com
    the user's browser will render the html page along with the image.

    Now the question(s).
    Since the image source in the above index.html file has a relative path
    images/banner.png
    and not an absolute path
    phantom007.com/images/banner.png
    then:

    1) How does the user's browser render the image that has a relative path in a remote location?
    2) Does the image file also gets transferred to the client's machine?
    3) If the answer to the above is "yes", in which medium / format does it get transferred? I mean via the headers or something else?



    Thanks for any inputs.
    Last edited by Mittineague; Feb 26, 2014 at 21:51. Reason: delinking example URLs

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,077
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by phantom007 View Post
    1) How does the user's browser render the image that has a relative path in a remote location?
    It adds the relative path to the path of the current URL. So for your example, if someone requests http://phantom007.com/ and there is a relative link to images/banner.png then the browser will concatenate those and request http://phantom007.com/images/banner.png.
    Note that an absolute link doesn't have to start with the domain, just a leading slash enough, i.e., /images/banner.png is also an absolute link.

    Quote Originally Posted by phantom007 View Post
    2) Does the image file also gets transferred to the client's machine?
    Of course. How else is the client supposed to see it?

    Quote Originally Posted by phantom007 View Post
    3) If the answer to the above is "yes", in which medium / format does it get transferred? I mean via the headers or something else?
    It will be a separate request. The browser will first download the index.html, find a reference to banner.png, and start to download banner.png as well. Every asset (css, javascript files, images) will always be downloaded separately, which is why it's always a good idea to combine as of them as possible.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    p7,

    Good explanation from Rémon but let me extend that to the redirections that this board normally discusses:

    RewriteRules are used to redirect a URI to another URI/URL via either a relative link (as you have asked about above) or an absolute link. If the absolute link is external (starts with http://{domain}/{path-to-file}), it's handled as a new URL to that file. If it's an INTERNAL absolute link, though, Apache looks to the server's root for the {path-to-file} then to the website's DocumentRoot. If you are careless enough to name your files etc/password (or the like), you could be causing significant security issues with your server. IMHO, it's best to try to avoid internal absolute links ... unless you know what's at your server's root AND do not allow visitors to enter their own URIs on your website.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •