Choose Your Theme
Warren Shea

Tutorial: This ain’t yo mom’s absolute pathing…sup?!

Monday, April 9th, 2012 at 4:39 pm

I should probably have a better title name considering what this tutorial is supposed to accomplish.

So as most of you hopefully know, putting a leading slash in a path refers to a root directory.

Example:
If the domain is http://www.worldofwarren.com/ and you link to
<a href=”/images/”>images</a>,
it will link to http://www.worldofwarren.com/images/

So what happens if you put 2 leading slashes in a path?
NOTHING LIKE THE ABOVE.

Purpose of this tutorial
To display the practical use of a URL with a leading double slash (//) in a path.
A URL with a double slash inherits the current protocol.

What you need to know/have
Basic HTML

Procedure
If you’re on an HTTP site (http://www.URL.com/) and you have

<img src=”//www.URL.com/images/logo.gif” alt=”” />,

then the image will reference http://www.URL.com/images/logo.gif

If you’re on an HTTPS site (https://www.URL.com/) and you have

<img src=”//www.URL.com/images/logo.gif” alt=”” />,

then the image will reference https://www.URL.com/images/logo.gif

Same code. But based on current protocal (HTTP or HTTPS), different results.

My ramblings
The // takes whatever protocol (HTTP or HTTPS) that the webpage is currently using and applies the referenced item to that. It’s awesome if you’re building secure and non-secure pages.

You wouldn’t need to use this on files that are within the same domain. In this case, relative pathing is probably better. But sometimes you link to files outside your domain.

For example, Google’s jQuery or SWFObject library.

Anyways, hope you learned something. I taught a lot of people this since learning it earlier this year, it’s awesome and so useful!

People are always asking “This form is supposed to be secure, but IE is prompting me with an alert that there are unsecure elements. PLZ FIX” and then you can be like “YO I JUST APPLY THE LEADING DOUBLE SLASH…sup?!”

One Response to “Tutorial: This ain’t yo mom’s absolute pathing…sup?!”

  1. Sophia says:

    Nice tutorial, now I know! :)

Leave a Reply