Forum Moderators: phranque

Message Too Old, No Replies

Omitting http: in src urls

         

Wes_Hooper

11:05 am on Apr 20, 2005 (gmt 0)

10+ Year Member



I've been spending a lot of time with logging / tracking code recently and I've noticed a few omitting the http: prefix for script and img src attributes.

<script language="JavaScript1.1" 
src="//example.com/example.js"></script>

(http://example.com/web/home/index.html?em=ParmValue)

Does anyone know why you would want to do this? I'm guessing it's so the same snippet of code can be used which will use the protocol of the page so you don't end up with http:// images on https:// pages?

If I'm correct, how widely is this supported? It would seem more elegant than doing the same thing in JavaScript, such as the Overture tracking.

var cc_protocol="http";
if(location.protocol == "https:")
{
cc_protocol="https";
}

The only other thing I could think of is that it makes the tracking URL's slightly shorter.

[edited by: txbakers at 7:18 pm (utc) on April 20, 2005]
[edit reason] examplified URLs [/edit]