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

前端 未结 2 1511
醉梦人生
醉梦人生 2021-02-19 18:08

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

相关标签:
2条回答
  • 2021-02-19 18:45

    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.

    0 讨论(0)
  • 2021-02-19 18:53

    Setting with javascript works for me:

    <head>
        <script>
            var str = document.location.protocol + '//' + document.location.host + '/';
            document.write('<base href="'+str+'">');
        </script>
    </head>
    
    0 讨论(0)
提交回复
热议问题