Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

The description of Yandex.Metrica explicitly says that URLs like //mc.yandex.ru/metrika/watch.js (no http: in front) that the web site owner has to insert into his pages are not erroneous. So for example this code:

<img src="//mc.yandex.ru/watch/00000"
     style="position:absolute; left:-9999px;" alt="" />

is claimed to be okay.

However the code validator thinks such URLs are not okay and I'd rather make the validator happy so that noone breaks the code later trying to "fix" it.

Why are these URLs not prepended with http:? What happens if I actually prepend them with http:?

share|improve this question
    
Unless this is simply a typo in your question, the (HTML?) validator fails because you are missing a " from the start of the attribute value. This has nothing to do with the structure of the URL. What code validator are you using? –  w3d Aug 26 '12 at 12:07
    
@w3d: That was a typo. I use the built-in validator of Visual Studio 2010 code editor. –  sharptooth Sep 10 '12 at 7:50

1 Answer 1

up vote 8 down vote accepted

I think the code validator is wrong. If part of a URL is missing then the other parts are filled in from the parent page. So for example, if an image is referred to from http://example.org/page1.html with src="pic.jpg" then the browser adds http://example.org/ before the src.jpg before it fetches the file. If the http: part of the url (the protocol) is missing then the protocol on the parent page will be used.

Why are they not prepended with http:? I'm guessing it's because if you have an https:// page then the images will automatically be delivered via https.

If you actually prepend them with http: and you have an https page then, depending on the browser, the user may get an error message saying that some of the content on the page isn't secure.

share|improve this answer
3  
+1 These are called relative references, defined in section 4.2 of the URI spec (no anchors). Here's a blog post with a less-technical overview. –  Su' Aug 24 '12 at 16:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.