Relative paths from the root in javascript
In ASP.NET you can use relative paths from the root of your domain by using the tilde character:
"~/Scripts/myScript.js"
In javascript, people sometimes wonder how to do this. We don't wan't to hard-code our domain, but we also don't want to use the './' notation, as our files could move around later. This would break things, and we might not know it.
One trick is to use '../../..', but you're never quite sure how many levels you need to move up.
The solutions is quite simple:
'/Scripts/myScript.js'
Starting with a '/' will create a relative path starting from your root.
Written by Peter Morlion
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#