Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a protocol-relative <base> tag?

Protocol-relative URLs make it convenient to include resources (images, CSS, JS) using the same schema (HTTP or HTTPS) as the original request, while keeping only a single copy of the cached page. The user agent then decides, whether or not to use HTTP or HTTPS (based on the URI of the HTML page).

We are using the <base href=".." /> tag and relative URLs to resources in the HTML.

An example:

<html>
<head>
  <base href="http://example.com" />
  <script src="js/foo.js" type="text/javascript" />
</head>

Is there any way that I can combine this? Protocol-relative URLs within a <base/> tag?

<base href="//example.com" />

My experiments esp. with Internet Explorer worked sometimes and sometimes not (sometimes even menu links didn't work, sometimes CSS images were not loaded).

Is there anything so that I can make it work or any recommendation if it is a good idea? I was not able to find information on sites like caniuse.com.

like image 990
StephenKing Avatar asked Feb 20 '14 12:02

StephenKing


Video Answer


1 Answers

We just attempted this with a site and Google's crawler did not understand how to use a protocol relative path as the base and we ended up with it indexing many broken urls.

I'm not sure if using a protocol relative path here is an acceptable value for the base path. Browser's seem to understand the protocol relative base just fine, but it could be that they are just more lenient in what they will accept.

like image 81
Jack Avatar answered Sep 19 '22 05:09

Jack