<base>
, with which the browser is given a base path for resolving relative links, is harmful and should not be used in a good layout. Instead, there is a fairly strict and flexible method for specifying the paths to resources.example.com/blog/record1
example.com/blog/record1
, will try to resolve the ../css/blog.css
link to example.com/blog/css/blog.css
example.com/blog/css/blog.css
. Perhaps this is not so bad, but in a situation where the address will be something like example.com/blog/tags/test
example.com/blog/tags/test
, the same link resolves to example.com/blog/tags/css/blog.css
example.com/blog/tags/css/blog.css
. Obviously, although the presence of the same file at several URLs can be realized, this is clearly not worth doing. Even if the css
folder is in the same place as the layout templates, the problem of relative addressing will not go anywhere.<base>
. According to specification:TheBASE
element allows authors to explicitly specify the base URI of the document.
If theBASE
element is specified, it must be present in theHEAD
section of the HTML document, before elements refer to external resources. The path information specified in theBASE
element affects only the URI in the document that contains this element.
base href="http://example.com/templates/"
in the element, we will force the browser to resolve all the above relative URLs into links to actually existing files lying on the same place. Having got rid of the habit of traveling up the directory tree in our relative path, we will get rid of these problems completely.<base>
for such purposes:www.example.com
www.example.com
browser will try to pull resources with example.com
example.com
( without www ). For CSS and images this is not so scary, but with scripts (especially HTC for Internet Explorer), cookies, ActiveX, Flash (if it means interaction with the server), and also if the user accesses the https protocol, the user will have more or less serious Problems. Consider also the difficulties when transferring a site to another domain (or using its engine for another site).<Base>
also affects the relative addresses used in the links, which are now also resolved according to the base path. Even if you specify base href="
example.com
example.com
/"
, there is a collision between domains, indicated in the first problem.<base>
and markup elements with the specified float
CSS property (for example, <div style="float: left;"> !</div>
), in the document you are viewing, will allow the mouse to select text in such elements. What connection can be here is not clear, but true.<base>
. You will not notice this if you specify the site root as the base path, but with any other folder used in this quality, the standard "medicine" for PNG stops working.<base>
tag altogether. And to solve the main stated problem, use other methods of working with relative links./
character (“slash”), then we can do without <base>
, while allowing the site to work from any domain and have some other benefits. I call this addressing, as opposed to the commonly used reference one, “semi-absolute” (because the protocol and domain are not specified, in contrast to the present absolute addressing)./templates/css/blog.css
. Such a link will work with any domain (as well as a protocol and port), since the default browser will use the directory of the document being called as the base directory (that is, for example, example.com/blog/record1
example.com/blog/record1
- for the browser, this path looks like the directory from which it views the index document). Relative links starting with a slash will be preceded by the browser used by the protocol and all other parts of the URL, ending with the current domain (and the port, if specified). Thus, the problem of addressing resources is solved without unnecessary problems with domains.url()
constructs and filters in CSS and hyperlinks between documents, this notation should be used if it is about working within the same domain. This will allow some freedom in handling files (for example, share the CSS file in the images
folder, or move it to a separate one), while maintaining strict code order and efficiency. Unfortunately, many IDEs used in web development do not have the appropriate settings for addressing resources, indulge too much relative addressing (especially with directory tree climbing), and even perceive existing files, but those indicated by the “semi-absolute” method, as non-existent resources. You should not depend on your tools, it is better to think with your head.file.txt
. Since the CNC engine was used, each page had its own catalog, and therefore, the flash drive did not work./flash/file.txt
. This resolved the problem on the server, however it ruined the life of the Flash technologist himself (when working in the local file system, such addressing is allowed in a way like C:/flash/file.txt
). Of course, there is a better solution.<base>
. To do this, you need to specify the base parameter in the flash insertion code with a value equal to the address of the desired directory in a “semi-absolute” form. That is, in my case, the implementation code of the flash drive looked like this:<object …>
<param name="base" value="/flash/">
…
<embed base="/flash/" src="/flash/01.swf" …>
…
special thanks to the authors of Habrakhabr for the “convenient" means of publishing the code
/
”. The flash technologist can now always be sure of the position of the flash drive in the web server space and indicate the paths to the resources in a convenient way (not necessarily as “semi-absolute”).Source: https://habr.com/ru/post/18116/
All Articles