SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    752
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question Using // instead of http://

    Hi

    I have seen people using // instead of http:// when including js/css in their page...anyone know why?

    Code:
    <script type="text/javascript"
    src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
    </script>

    Thanks

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    If your page is requested over https, you'll get a warning about including non-secure content if you link scripts over http. By starting your links with //, the browser will use the same protocol that the page is served by.

  3. #3
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,314
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    It's a scheme relative URL. So if your page is https, then the js/css request will also be https. Works everywhere, I believe, except that I've read IE8 will issue the request twice, which would be detrimental to performance since the number of HTTP requests is one of the most significant factors. But if IE8 isn't a concern, then there's no reason you can't use scheme relative URLs everywhere.

    EDIT: People keep beating me to the punch lately.
    "First make it work. Then make it better."

  4. #4
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    752
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    so will it even work if the page requesting is https and googleapis.com does not support https?

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by cancer10 View Post
    so will it even work if the page requesting is https and googleapis.com does not support https?
    No, the server hosting the scripts must be able to serve them via https for that to work.

    Edit: @Jeff Mott - I hadn't heard that about IE8 before, that's useful to know.

  6. #6
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    752
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    oh ok thanks everyone for the responses...

  7. #7
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    752
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    It's a scheme relative URL. So if your page is https, then the js/css request will also be https. Works everywhere, I believe, except that I've read IE8 will issue the request twice, which would be detrimental to performance since the number of HTTP requests is one of the most significant factors. But if IE8 isn't a concern, then there's no reason you can't use scheme relative URLs everywhere.

    EDIT: People keep beating me to the punch lately.
    Does IE make double request, one for http and the other for https?? is it?

  8. #8
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Just to clarify on the IE issue, according to this blog post by Paul Irish:
    When used on a <link> or @import for a stylesheet, IE7 and IE8 download the file twice. All other uses, however, are just fine.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •