0

To deploy a recent project I must use absolute pathing but for testing locally outside a server I'd like to use relative pathing for most of links to external scripts and images.

On another project I'd like to dynamically change relative pathing to site relative when the project is loaded from a server.

For both projects I'd ideally like to employ some reusuable method with javascript or jQuery that would automatically redefine these links depending on the testing environment.

So I know I need to set up some type of global path variable.

And then in my HTML markup prepend the links with this variable.

But not sure how to implement.

Anyone have a solution?

1
  • When you say "testing locally outside a server" do you mean using file:// protocol? Commented Jun 9, 2012 at 6:50

1 Answer 1

1

The best (and least annoying) way I use is mapping to local host.

Let's say you work on awebsite.com

  • Keep all your links as absolute
  • Map awebsite.com to 127.0.0.1 on your hosts file
  • add awebsite.com to your virtual hosts file

It's done, now you access your testing environment as awebsite.com

When you want to browse the online website, just comment the line you added in hosts file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.