Reputation:
I am wondering what the best method is. E.g.
<script type="text/javascript" src="<%= GetBaseURL() %>Scripts/jquery-1.4.1.min.js"></script>
renders
<script type="text/javascript" src="http://www.mywebsite.com/Scripts/jquery-1.4.1.min.js"></script>
Is there any danger or performance hit doing it this way?
Upvotes: 2
Views: 329
Reputation: 92792
You could even use the relative url starting from the web root:
/Scripts/jquery-1.4.1.min.js
^-- note the slash at the beginning
gets always translated to the same path on the server, no matter in what directory your page resides: in other words, whether the document is at http://example.com/some/path/index.html
or http://example.com/index.html
, the browser will resolve /Scripts/jquery-1.4.1.min.js
into http://example.com/Scripts/jquery-1.4.1.min.js
- using only the protocol and domain of the base document, ignoring the path.
Upvotes: 1
Reputation: 449823
Is there any danger or performance hit doing it this way?
No. Whether you specify a relative or an absolute URL doesn't matter: It will be translated into an absolute URL by the browser anyway.
Using an absolute URL has an upside: It makes it easy to move all static resources to a different server if necessary (e.g. to follow Google's page optimization rules). It's a good thing to have if the variable is available.
Upvotes: 3
Reputation: 14898
not at all. the browser resolves it to that at the end of the day anyway.
Upvotes: 0