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

For instance Google Analytics uses document.location.protocol in the boilerplate for tracking:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

instead of

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = '//www.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

The ssl. sub-domain is a mute argument as https://www.google-analytics.com/ga.js works perfectly well.

Knowing Google this most likely is not an oversight. Is there an issue with certain browsers not supporting the // protocol honouring shorthand or is there something else I'm missing?

EDIT: This does not just apply to Google Analytics (different sub-domain example). The same thing appears on the Font Loader API page:

wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
share|improve this question
    
Might get a better response rephrasing your question to ask about the technical issue rather than why Google is doing something. You're not going to get a real answer to the second (unless we see another Googler response here, which would be cool). –  JasonBirch Aug 4 '10 at 8:10
    
Slight edit in an attempt to make it more agnostic. Any other suggestions? –  Metalshark Aug 4 '10 at 8:25
add comment

3 Answers

At least has one problem in IE because it causes double downloads: http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/

share|improve this answer
    
Only applies to stylesheets in IE7/8 - but thanks for the heads up. –  Metalshark Aug 4 '10 at 11:39
add comment

You already pointed out the difference in the case of Google Analytics, namely that the secure version is on https://ssl. instead of http://www.. While a secure version of the www may work, it could also be different to the ssl version:

  • Different certificates for the ssl version and www version.
  • Different code on each version.
  • Different cookies set, specific to the SSL domain.

I don't know if any of these apply to Google though. From a glance the code looked to be the same.

share|improve this answer
    
Another example would be the font loader code.google.com/apis/webfonts/docs/webfont_loader.html here there is no difference in domain. Every boilerplate example of their code follows the same pattern. –  Metalshark Aug 4 '10 at 13:26
    
In that case, they are using the same domain. Maybe there are some archaic browsers that don't recognise the // protocol? –  DisgruntledGoat Aug 5 '10 at 13:24
    
That was the thinking, but which ones, more importantly which ones that also support web font? Does it allow more parallel behaviour (quantum physics style, by reading the proto it alters the state of the browser)? I've thoroughly tested and am yet to see the logic... –  Metalshark Aug 5 '10 at 17:57
add comment

This Stack Overflow answer makes some good points.

It would be important to explicitly specify the protocol so that the target asset is loaded correctly within a document opened from a local drive (file:) or when using "iframe magic" (about:).

share|improve this answer
add comment

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.