How well-supported is <base>? Should I be using it?
So I just found out today that you can use <base href=""/>
to specify the base URL for relative URLs. It seems so awesomely convenient, and I'm surprised why it's not mentioned more often. Is there any reaso开发者_开发知识库n to not use it? It's not anything new, right?
It's part of the HTML 4.01 specification (and also the latest draft of the HTML 5 spec). You're good to go.
From section 12.4 of the HTML 4.01 spec:
This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.
In terms of support from browsers you shouldn't have any problems as has been said. One word of caution though is that it has caused me confusion in debugging things. Because it is so rarely used I hae found that I have not noticed it and become very confused about how things are working when the file doesn't exist, etc. As long as it isn't a readability problem though then I'd say go for it. :)
Also be sure you use it properly. I believe that older versions of IE used to let you mark only certain parts of your page with the base tag and only apply that base to the elements it contained. I believe this is not widely supported and only the page level application of this element is valid. Check Donut's spec link for details on how to use and as always be cautious of out of date/incorrect info on the net. :)
Reason not to use it: Possibly adding complexity.
Depending on the existing complexity of your site, if you're using templates, etc., later additions, modifications, or plug-ins that require resources may not expect an altered relative path. Or the other way around -- you may inadvertently be adding dependencies, akin to "hard-coding" in other programming aspects.
Barring this, it does work, and you should be fine in using it. (I don't; haven't had to.)
精彩评论