Why it’s ok to replace “http://” with “//” in a script

At least a dozen heavily trafficked sites use only // instead of https:// or http:// when linking to a *.css file, *.js file and sometimes, even when linking to other resources like external links. It seems to me that both versions are correct, using only // when linking to a script or style file. A relative URL without a scheme (http: or https:) is valid, per RFC 3986: “Uniform Resource Identifier (URI): Generic Syntax”, Section 4.2.

Sites like Youtube, Google, CNN, WordPress, TechCrunch, Twitter, Reddit use only // instead of http:// or https:// when linking to resource files or external links.

I can’t provide here the impact of excluding a few characters but, for heavily trafficked sites can make a difference I suppose eliminating the loading time and bandwidth.

Try it Yourself / Live DEMO