rxohbg
Last Updated: February 25, 2016
·
702
· alexanderbrevig

Drop protocol in URIs

So this protip is very simple.

DO: //somesite.com/somepath/somefile.js or relative /somepath/somefile.js

DON'T: http://somesite.com/somepath/somefile.js

If you use //somesite.com/somepath/somefile.js for all your references, the browser will fill in the protocol for you. So if you're visiting the page with https, the ref will become https://somesite.com/somepath/somefile.js.

I recently had to make on of my sites be HTTPs compliant. Luckily it was as easy as setting up an SSL and change the default protocol for my sites.
Because of this trick, I had no insecure resources and no warnings on my site.

Excellent!

3 Responses
Add your response

16109

Should there be a colon here? https//somesite.com/somepath/somefile.js.

over 1 year ago ·
16114

Of course

over 1 year ago ·
23414

I was hoping you would answer "NO because you shouldn't fill in the protocol" ;) awesome tip though

over 1 year ago ·