I am trying to figure this problem out. With HTML apparently you are allowed to add two forward slashes to a src link, and it is supposed to interpret that as a web link.
<script type="text/javascript" data-referrer="false" src="//branding.vcu.edu/bar/academic/latest.js" data-color-top-campaign="graydark"></script>
The problem I am having is that the two forward slashes in my link are being interpreted as a file location, not a website. This is also breaking other external javascript files that I am including in my website that use the same double slash format. You can see in the screenshot I provided that it is interpreting them as files.
I am also using Twitter Bootstrap if that affects anything. I would really appreciate it if someone could point me in the right direction here. Thanks!
Here’s the source header I am working with in-case that helps:
<head>
<meta charset="utf-8">
<title>Motor Control Lab VCU</title>
<!-- Mobile Fixes -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- Favicon -->
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<!-- Bootstrap Style Sheet -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- load all FontAwesome styles -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<!-- load FontAwesome javascript file -->
<script defer src="js/all.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<!-- Widens the default container -->
<style>
@media (min-width: 1200px) {
.container {
max-width: 1350px;
}
}
</style>
<script type="text/javascript" data-referrer="false" src="//branding.vcu.edu/bar/academic/latest.js" data-color-top-campaign="graydark"></script>
</head>
3
Answers
The
//
notation is used to retain the protocol (http:, https:, or file:) of where your website is served from.If you’re looking at it locally from a file:// url, it will look for a file on disk, if you’re looking at it served from a web-server, it will go to http(s):// instead.
A relative URL starting with
//
means “Use the same URL scheme as the current document, but a different hostname and everything else”.It is resolving to a
file:
URL because the HTML document is loaded from afile:
URL.Either load the HTML document from an
http:
orhttps:
URL or change thesrc
attribute from a relative URL to an absolute URL (i.e. put the URL scheme in explicitly).srcs with double slashes are “protocol-relative”. It uses whatever protocol(http, https, file) was used to load your website. Since you are loading the website locally it assumes you want to load the script from file://path/to/file which is an absolute url. Use ./ instead