Search code examples
urlpathprotocols

What's the difference between root-relative and protocol-relative url paths?


In practice, I've seen that a root-relative URL like /some-resource will automatically resolve to the same same protocol and domain as its parent page. That said, Googling for "protocol-relative url" returns examples like //some-resource, also warnings that nowadays its an "anti-pattern". So, why/when would I use a protocol-relative url vs root-relative? Seems as if root-relative works fine?


Solution

  • @user2864740

    //resources.mysite.bar/foo.gif” would be “correct” from both HTTP and HTTPS pages hosted on “www.mysite.bar”. Under an HTTPS page there would not be security warning for mixed-HTTP/HTTPS content. Root-relative would restrict to “www.mysite.bar” content alone.

    Thanks @user2864740