Can I change all my http:// links to just //?

后端 未结 7 1506
后悔当初
后悔当初 2020-11-22 01:12

Dave Ward says,

It’s not exactly light reading, but section 4.2 of RFC 3986 provides for fully qualified URLs that omit protocol (the HTTP or HTTPS) a

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 01:47

    Is this completely cross-browser compatible? Are there any other caveats?

    Just to throw this in the mix, if you are developing on a local server, it might not work. You need to specify a scheme, otherwise the browser may assume that src="//cdn.example.com/js_file.js" is src="file://cdn.example.com/js_file.js", which will break since you're not hosting this resource locally.

    Microsoft Internet Explorer seem to be particularly sensitive to this, see this question: Not able to load jQuery in Internet Explorer on localhost (WAMP)

    You would probably always try to find a solution that works on all your environments with the least amount of modifications needed.

    The solution used by HTML5Boilerplate is to have a fallback when the resource is not loaded correctly, but that only works if you incorporate a check:

    
    
    
    

    I posted this answer here as well.

    UPDATE: HTML5Boilerplate now uses

提交回复
热议问题