My coworker blew my mind this morning. Anyone working with secure sites knows that there’s often security flags thrown if you’re referencing a file via
http:// when the site is under
https://. To avoid these, in the past I have always done an if/else in whatever language the site was written. For example:
/* pseudocode */
In debugging some code on our site, I noticed that the aforementioned stylesheet was only linked in the Secure check, and forgotten in the else.
Lo and behold, you can avoid these confusions by including your external references without the protocol included. That’s right, drop off the
http: and just leave two slashes and the link, as follows:
It works perfectly and you can simplify your server code. C’est magnifique! I’m not sure about older browsers, so if you run into an issue, leave a comment and I’ll note my post accordingly.