Zach’s ugly mug (his face) Zach Leat­herman
Recent Activity
  1. Shib Willoughby Seth Falco Cthos Lukas The True Source of Value Matthias Zöchling majjo Michael
    “AI, make the website good”

    25 reposts 9 replies 2 mentions

  2. Christopher Kirk-Nielsen
  3. Doug Parker 🕸️
    Table of Contents Web Component

  4. PDFops Joe Dakroub Tobias Fedder katherine Rob Anneke Christian Alder Clayton Errington 🖥️
    Table of Contents Web Component

    1 repost

  5. William Allyn Nova (he/they) Charity Gamble Brian David Germany Font Awesome Cumulonimbus Font Awesome
    Icon Fall Web Component

    2 reposts

Relative URLs including the Domain

763 02 October 16, 2008

Just a neat little trick I saw while browsing the source code of Google Calendar. In some of their CSS files, they link to background-images using URLs that include everything but the protocol, which is something I hadn’t seen before.

The most common usage of a relative URL is linked from the root (note the slash at the beginning), like so:

/web/wp-content/themes/hemingway/images/title.png

You can also use ../ to navigate up a directory in your path, but that’s boring. The interesting question is: what if I wanted to load content from a separate domain, while at the same time transparently using the protocol used on my page?

Do what Google Calendar does and use the following style:

//calendar.google.com/googlecalendar/images/calendar_sm2_en.gif

Note the lack of http: or https: from the URL. If this page were hosted on https (we don’t pay for certificates around here, so you’ll have to put up with the security warning), the last image source will load from https as well at no additional development cost.

This seems like it would be especially useful if you were using the YDN Performance tip to Split Components Across Domains. Remember, we’re not just talking images. This involves how the browser resolves URLs, so could be used inside href tags, css urls (as Google Calendar did), etc.


< Older
ALARMd is a Google Code Project
Newer >
Dear IE6: Please Cache my Images.

Zach Leatherman IndieWeb Avatar for https://zachleat.com/is a builder for the web at Font Awesome and the creator of Build Awesome (née IndieWeb Avatar for https://www.11ty.devEleventy/11ty), an award-winning open source website generator. He measures website performance with speedlify and at one point became too fixated on web fonts. He has given 89 talks in nine different countries at events like Beyond Tellerrand, Smashing Conference, Jamstack Conf, CSSConf, and The White House. Formerly part of CloudCannon, Netlify, Filament Group, NEJS CONF, and NebraskaJS. Learn more about Zach »

2 Comments
  1. Avatar for Radoslav Stankov
    Radoslav Stankov
    I found the behavior of // recently when by mistake in a project I wrote // instead of / and the file was something. And I thought that i was some server error because it was on the test server.
  2. Avatar for Porsche
    Porsche
    I usually use full url to link all the content, always less chance to make a mistake
Shamelessly plug your related post

These are webmentions via the IndieWeb and webmention.io.

Sharing on social media?

This is what will show up when you share this post on Social Media:

How did you do this? I automated my Open Graph images. (Peer behind the curtain at the test page)