5

I often use the // relative URI hack. Example:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

Mostly because of this post: Is it valid to replace http:// with // in a <script src="http://...">?.

However, a guy I am working with on a project says this doesn't work on Mac (Chrome, Firefox, and Safari) or iDevices.

Not having a Mac or said devices, I can't verify it, and it works fine on Windows. Can anyone confirm this?

Community
  • 1
  • 1
Peter C
  • 6,219
  • 1
  • 25
  • 37
  • Your guy is wrong. Protocol-relative URLs are defined on a very low level. They are not OS specific. Hang on, searching for duplicate.... – Pekka Aug 19 '11 at 22:32
  • possible duplicate of [Preventing secure/insecure errors by using protocol relative URLs for image source](http://stackoverflow.com/questions/4303633/preventing-secure-insecure-errors-by-using-protocol-relative-urls-for-image-sourc) – Pekka Aug 19 '11 at 22:34
  • @Pekka: Thanks. I like this technique, even though I don't think we'll be serving anything under HTTPS. – Peter C Aug 19 '11 at 22:35
  • Circumstantial evidence that mobile safari supports protocol relative URLs: http://getsatisfaction.com/viglink/topics/link_broken_in_mobile_safari – Pekka Aug 19 '11 at 22:49
  • I know this thread is old and dead but just for anyone else who stumbles along here, I just tested this on a Mac and the relative URI trick doesn't work very well. It puts file:// on the front instead of the http/https you probably want. It did work in iOS7 though. – club_lowlow Feb 12 '14 at 22:07

1 Answers1

4

I can't test it as I don't have a Mac, but there is no reason to believe that mac browsers do not follow RFC 3986 Section 4.2 when resolving URLs.

Your friend probably meant something else.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • I don't think he meant something else, as he said "We are doing best practices, full URL paths for anything not hosted on our site from here on out.", which I can't really disagree with, since it's a two person project and he's the leader... – Peter C Aug 19 '11 at 22:51
  • @alpha have you asked him why? – Pekka Aug 19 '11 at 22:52
  • Well, presumably because it doesn't work (for him) on Mac browsers and Mobile Safari. Anyway, since I'm pretty sure we won't be serving anything over HTTPS, I'll just use the http: prefix, but for future reference it would be nice to know if that is indeed the case. It seems not. Thanks. – Peter C Aug 19 '11 at 23:00
  • @alpha no problem. If your colleague comes up with something substantial regarding the issue, please leave a comment here - but from all I can see, there is nothing to it – Pekka Aug 19 '11 at 23:02