What protocol is loaded when using protocol-relati

2019-02-14 06:10发布

问题:

I just started to test the idea behind "protocol less Urls".

The problem I´m looking to solve is: on a https page I need to load an external css file from http.

Doing this the "normal" way results in failure... the css file is blocked. (Just testing with chrome for now).

So my question is: Will "protocol less Urls" load the file from http/https/both?

回答1:

If you're referring to URLs like www.example.com/style.css, that won't work because the protocol is completely missing; a browser will treat www.example.com as some kind of directory path name.

If you're referring to URLs like //www.example.com/style.css, that is a protocol-relative URL; it uses the same protocol as what the browser is already using to request the referring page. For example, if the browser had requested a page with https://www.example.com, then that URL will be requested over HTTPS and not HTTP.

Browser support for these URLs is generally pretty good; see the following questions:

  • Is it valid to replace http:// with // in a <script src="http://...">?
  • Can I change all my http:// links to just //?


标签: url protocols