2

Is it possible to automatically detect whether or not the page is accessed via http or https and then include a https://url.js or http://url.js ?

Is javascript included via https any different? I'm talking about cache age and so on?

Thanks, Wesley

1 Answer 1

11

Use a protocol-relative link, starting with // instead of http or https:

<script type='text/javascript' src="//path/to/file.js"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

Is that supported in every browser? Interesting.
@Wesley I believe so. I think it's been part of the spec since the mid 1990's and am trying to find the W3 documentation now.
This question has a bit of interesting additional information about protocol-relative URL's when used in HTML email stackoverflow.com/questions/4303633/…
width domain name will be like //domain.net/path/to.file.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.