If you’d like to contribute a bit of your time back to the benefit the larger web community, I’ve collected a few mini-projects that’ll have high impact. They’re together in an issue tracker of an otherwise empty github repo: github.com/paulirish/lazyweb-requests.
Allowing the snippet to request over HTTP opens the door for attacks like the recent Github Man-on-the-side attack. It’s always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true.
There’s this little trick you can get away with that’ll save you some headaches:
1
<imgsrc="//domain.com/img/logo.png">
If the browser is viewing that current page in through HTTPS, then it’ll request that asset with the HTTPS protocol, otherwise it’ll typically* request it with HTTP. This prevents that awful “This Page Contains Both Secure and Non-Secure Items” error message in IE, keeping all your asset requests within the same protocol.
*Of course, if you’re viewing the file locally, it’ll try to request the file with the file:// protocol.
We use this trick in the HTML5 Boilerplate for a clever request of jQuery off the Google CDN:
Technically, this is called a “network-path reference” according to RFC 3986. Oh and if you want to be truly correct, you’ll use the term “scheme” instead of “protocol” when talking about URLs.
Yes of course, wouldn’t that be nice… So I worked with the Google Analytics javascript lead developer (God, I love working at google) to see if we could do this… turns out we can’t. There is an edgecase bug in IE6 that causes a dialog to blow up… under some security settings (unsure if they are default) when requesting from the non-‘ssl’ subdomain. screenshot here. So feel free to take 40 bytes off your GA snippet if you don’t care about IE6.. otherwise you’re gonna need that ternary operator. :)
2011.12.24. Eric Law (from the IE team) chimes on why IE6 doesnt play well GA…
The reason this doesn’t work in IE6 is that the server is using SNI to deduce what certificate to return. XP (and thus IE6) doesn’t support SNI in the HTTPS stack. See for details.
When kicking off a new project, I’ve always wanted to take with me all the kickass tricks I learned on the previous one. This project has been on and off for the last 2.5 years with a whole lot of on lately. Finally, HTML5 Boilerplate is ready to share.
It’s essentially a good starting template of html and css and a folder structure that works. But baked into it is years of best practices from front-end development professionals. Take a peek through the source to get a feel of what’s inside. And if you think there’s too much? Delete key that badboy.
I’m very interested in your contributions.. what else deserves to be in this base template?