web developers: how do you deal with absolute paths when pre-testing?

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,753
6,782
136
I'm working on a project with multiple images and Flash files that are in a shared directory on the server. I need to be able to reference them from subdirectories. Question 1: Is using the absolute path the best way? If so, see next question. If not, please share your insights.

Question 2: when using absolute paths, how do you perform testing without actually loading it on the server? Most of the servers I use are remotely hosted. I don't want to have to upload everything just to make sure it all works because I can do that locally on my computer, but if I do the testing on my computer, I don't want to have to go through each file and edit the pathname on the computer to the absolute path name of the server. I don't know if there is a workaround for this, so maybe just uploading and testing or renaming are the best (and only) options. For example:

On my PC:
/files/flashmovie.swf
/projects/coolstuff.html
In coolstuff.html: embed ../files/flashmovies.swf

On the server:
www.mysite.com/files/flashmovie.swf
www.mysite.com/projects/coolstuff.html
In coolstuff.html: embed www.mysite.com/files/flashmovies.swf

It's either upload and test OR rename on upload, from what I see. Alternatives = ?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Simple, I don't use absolute paths.

EDIT: Why wouldn't the code that you run locally work on the server (in the example you posted)?

EDIT 2: You can always reference the root directory with a leading slash (embed /files/flashmovie.swf). There's not need to provide the server/domain in an href unless it's to an external server/system.
 

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,753
6,782
136
Originally posted by: MrChad
Simple, I don't use absolute paths.

EDIT: Why wouldn't the code that you run locally work on the server (in the example you posted)?

In the example, it would work. But when I upload it from my local computer, I would have to update the path if I moved the file somewhere else on the server than where it was in my local file structure. If I used the absolute path, then I could move the file anywhere on the server, in any directory, without worrying about whether an image or Flash file will load. However, if I put that absolute path in the code first, then it won't work on my computer, because it will be referencing www.mysite.com.
 

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,753
6,782
136
Originally posted by: JonnyBlaze
when i used to dabble in web sites i had apache running locally.

Yeah, but I'd still have to worry about the actual domain name in the code :\
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: Kaido
Originally posted by: MrChad
Simple, I don't use absolute paths.

EDIT: Why wouldn't the code that you run locally work on the server (in the example you posted)?

In the example, it would work. But when I upload it from my local computer, I would have to update the path if I moved the file somewhere else on the server than where it was in my local file structure. If I used the absolute path, then I could move the file anywhere on the server, in any directory, without worrying about whether an image or Flash file will load. However, if I put that absolute path in the code first, then it won't work on my computer, because it will be referencing www.mysite.com.

:confused:

I don't understand. Your local file structure should always mirror your deployment file structure. You may need to set up virtual directories on your server to achieve this, but that still shouldn't affect your relative path references.
 

JonnyBlaze

Diamond Member
May 24, 2001
3,114
1
0
Originally posted by: Kaido
Originally posted by: JonnyBlaze
when i used to dabble in web sites i had apache running locally.

Yeah, but I'd still have to worry about the actual domain name in the code :\

the code you posted under On my pc should work on both.
 

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,753
6,782
136
Originally posted by: MrChad
Originally posted by: Kaido
Originally posted by: MrChad
Simple, I don't use absolute paths.

EDIT: Why wouldn't the code that you run locally work on the server (in the example you posted)?

In the example, it would work. But when I upload it from my local computer, I would have to update the path if I moved the file somewhere else on the server than where it was in my local file structure. If I used the absolute path, then I could move the file anywhere on the server, in any directory, without worrying about whether an image or Flash file will load. However, if I put that absolute path in the code first, then it won't work on my computer, because it will be referencing www.mysite.com.

:confused:

I don't understand. Your local file structure should always mirror your deployment file structure. You may need to set up virtual directories on your server to achieve this, but that still shouldn't affect your relative path references.

True. I'm probably making more of an issue out of this than I should. I was just wondering if there was a different way than manually changing the path to absolute on the server with the domain name or mirroring the file structure. In reality, mirroring the file structure is what should be done, you're absolutely right.
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: Kaido
Originally posted by: MrChad
Originally posted by: Kaido
Originally posted by: MrChad
Simple, I don't use absolute paths.

EDIT: Why wouldn't the code that you run locally work on the server (in the example you posted)?

In the example, it would work. But when I upload it from my local computer, I would have to update the path if I moved the file somewhere else on the server than where it was in my local file structure. If I used the absolute path, then I could move the file anywhere on the server, in any directory, without worrying about whether an image or Flash file will load. However, if I put that absolute path in the code first, then it won't work on my computer, because it will be referencing www.mysite.com.

:confused:

I don't understand. Your local file structure should always mirror your deployment file structure. You may need to set up virtual directories on your server to achieve this, but that still shouldn't affect your relative path references.

True. I'm probably making more of an issue out of this than I should. I was just wondering if there was a different way than manually changing the path to absolute on the server with the domain name or mirroring the file structure. In reality, mirroring the file structure is what should be done, you're absolutely right.

Again, if you're not referencing an external server, there is never a need to include the full server or domain name in your hrefs.
 

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
I never develop on local machines. At least put it in a different directory (same level) on the server (or use a dev server) and use relative paths.
 

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,753
6,782
136
Originally posted by: rh71
I never develop on local machines. At least put it in a different directory (same level) on the server (or use a dev server) and use relative paths.

Why don't you ever develop on local machines?
 

apinomus

Senior member
Dec 14, 2005
394
0
0
I use Dreamweaver and create a Site for each website I'm making. In your case I would set the root of my DW Site to C:\website\ if your local path was C:\website\projects\coolstuff.html . Then use paths relivant to the root of the site as /projects/coolstuff.html .

This is especially useful when laying out your template or something that's used on every page. You almost always would want your template stuff relative to root. If you're just linking between documents in the same folder, I use relivant to document. It's personal preference really...
 

Kaido

Elite Member & Kitchen Overlord
Feb 14, 2004
50,753
6,782
136
Originally posted by: apinomus
I use Dreamweaver and create a Site for each website I'm making. In your case I would set the root of my DW Site to C:\website\ if your local path was C:\website\projects\coolstuff.html . Then use paths relivant to the root of the site as /projects/coolstuff.html .

This is especially useful when laying out your template or something that's used on every page. You almost always would want your template stuff relative to root. If you're just linking between documents in the same folder, I use relivant to document. It's personal preference really...

Yeah, that's a smart idea. The other designer is using Dreamweaver and I'm hand-coding (aka cleaning up Dreamweaver's mess). I'm also adding on custom PHP goodies and JavaScripts and whatnot. Things don't always mix, but currently we have the luxury of working on a shared server, so it's not too bad.
 

fs5

Lifer
Jun 10, 2000
11,774
1
0
www.publicsite.com/app/serverdir/ <- root directory on server
localhost/home/user/dev/html/rev1/ <- local directory

just as long as the folder structure under serverdir/ and rev1/ are the same then you'll have no problems.
<img src="images/omg.png">
<a href="anotherfolder/link.html">link</a>
etc...

Just don't include the site url or absolute path.