Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:23:17+00:00 2026-06-17T23:23:17+00:00

Possible Duplicate: Is there any downside for using a leading double slash to inherit

  • 0

Possible Duplicate:
Is there any downside for using a leading double slash to inherit the protocol in a URL? i.e. src=“//domain.com”

I have seen the following logic in many places, f.ex the analytics script:

script.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://example.com/cdn.js';

But to my knowledge, you could just as well do:

script.src = '//example.com/cdn.js';

and it should use whatever protocol that is currently used. Or am I missing something? What is considered “best practice”?

I’m not looking for browser compatibility answers, google already recommends // for CDN scripts so that shouldn’t be the case here.

Here’s a fiddle, but it doesn’t really say much more than it seems to work in this setup: http://jsfiddle.net/6ZGyb/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:23:18+00:00Added an answer on June 17, 2026 at 11:23 pm

    A bit of background:

    The additional JavaScript protocol wrapper is usually there to assure all browsers’ support for such relative path URLs. You’re right to assume most current browsers handle such URLs properly anyway, however for the sake of being able to sleep with a rested mind, it’s still generally considered a good practice to assume not all user-agents accessing your web pages are as savvy as we’d expect them to be (or, supporting RFC 1808 Section 4, RFC 2396 Section 5.2, or RFC 3986 Section 5.2 as already mentioned in Is there any downside for using a leading double slash to inherit the protocol in a URL? thread as @Bruno pointed out in the comment)

    Compatibility concerns:

    Imagine a scenario where contents containing such relative paths are accessible ‘out-of-context’, e.g. in a email client. In this case such relative paths might be parsed to their fully qualified paths the wrong way and cause all kinds of problems, from users not being able to see contents properly, to accessing contents they really shouldn’t be. To avoid any such issues, use of relative paths should always be limited to in-context cases where the parser of the parent document (opener application) can determine the complete absolute path to the resource in question. You should only expect relative paths to work properly when they’ll be accessed by same or compatible protocol.

    Security concerns:

    Another possible concern that was raised is:

    Could such relative protocol URLs be exploited in any way by accessing (parsed URL) parent document contents by various exchange
    protocols, and if such JavaScript wrapper serves a purpose of
    deflecting such access.

    The (long) list of official IANA registered URL schemes suggests there’s a lot of potentially worrying exchange protocols that could be used by exploiters, however JavaScript wouldn’t do much anything on user-agents that don’t have support for JavaScript (or is disabled by user). My answer would, with that in mind, have to be – no (for the ‘JavaScript protecting access using other protocols’ part).

    As for the remaining part of the raised concern (‘could such relative protocol URLs be exploited in any way’), the answer depends on how well this was considered when setting up the web server serving any such contents, does it even support/handle such requests (if it doesn’t then it’s a non-issue), and what possible vectors of attack/content theft were considered before deployment. In other words, it’s a web server administration problem and certainly not something web designers/programmers could/should answer. Each end-user accessible protocol should have its own set of security protocols on top of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Are there any cons to using color names in place of color
Possible Duplicate: Are there any good reasons for using hex over decimal for RGB
Possible Duplicate: Is there any reason to declare ivars if you're using properties exclusively
Possible Duplicate: Are there any disadvantages to always using nvarchar(MAX)? Is there a general
Possible Duplicate: is there any other way of creating an object without using “new”
Possible Duplicate: Is there any hash function in PL/SQL? I have a column with
Possible Duplicate: Is there any working memory profiler for Python3 I have some script
Possible Duplicate: Is there any way to determine text direction from CultureInfo in asp.net?
Possible Duplicate: Is there any reason to use the 'auto' keyword in C /
Possible Duplicate: Overriding the power button in Android Is there any possible way I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.