In my html files I use root-relative paths such as: <link rel="stylesheet" href="/css/screen.css" type="text/css" />
The Web Preview does not work even though the path is also relative to the top level of the project, I have to use paths relative to the current document. <link rel="stylesheet" href="css/screen.css" type="text/css" />
Is there some way to get Web Preview to work with root-relative paths for html development? -Gianni
On 2009-Apr-16, at 12:34 AM, Gianni wrote:
In my html files I use root-relative paths such as:
<link rel="stylesheet" href="/css/screen.css" type="text/css" />
It's all about the context. When loaded from a web server, a browser will interpret this as relative the the server's DocumentRoot. When loaded from a local file, the browser will interpret this as relative to the root of your file system.
You would get conflicting results either way. For instance, if you had a file at "/files/index.html" and it referenced "/files/style.css", it would work when loaded from a web server. But if the browser assumed that paths in local files beginning with '/' should be relative to the current document's parent directory, then the above reference would be interpreted as "/files/files/style.css".
In other words, you're damned if you do, damned if you don't.
This works everywhere because it is truly relative. I would switch to this method wherever possible… which is not always practical. Honestly, my "preview" is to upload to a web server and reload the page in my browser. As an alternative, don't forget that your computer has a web server already installed on it. With a little setup, you could preview things by connecting to http://localhost/.
Is there some way to get Web Preview to work with root-relative paths for html development?
There are variables you can set for a project, like TM_PROJECT_SITEURL. I'm not sure where such variables are documented or if they affect the behavior of the Web Preview, but perhaps there's something similar that can tell the Web Preview to insert a path before links beginning with '/'.