13
<head runat="server">
    <meta charset="UTF-8" />
    <title>Make Games with Scirra Software</title>
    <meta name="description" content="Game making with Construct." />
    <meta name="keywords" content="game maker, game builder, html5, create games, games creator" />
    <link rel="stylesheet" href="~/css/default.css" />
    <link rel="stylesheet" href="~/plugins/coin-slider/coin-slider-styles.css" />
    <link rel="shortcut icon" href="~/images/favicon.ico" />
    <link rel="apple-touch-icon" href="~/images/favicon_apple.png" />
    <script src="~/js/googleAnalytics.js"></script>
</head>

Renders as:

<head>
    <meta charset="UTF-8" />
    <title>Make Games with Scirra Software</title>
    <meta name="description" content="Game making with Construct." />
    <meta name="keywords" content="game maker, game builder, html5, create games, games creator" />
    <link rel="stylesheet" href="../css/default.css" />
    <link rel="stylesheet" href="../plugins/coin-slider/coin-slider-styles.css" />
    <link rel="shortcut icon" href="../images/favicon.ico" />
    <link rel="apple-touch-icon" href="../images/favicon_apple.png" />
    <script src="~/js/googleAnalytics.js"></script>
</head>

Why is the JavaScript URL ~/ and not ../?

1 Answer 1

23

Strange implementation indeed, but unfortunately that is the way ASP.NET handles this. Here is what I do to compensate:

<script src="<%=ResolveClientUrl("~/js/googleAnalytics.js")%>"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

You probably only need ResolveUrl(), as ResolveClientUrl creates the whole URL, rather than just the relative path.
Thanks, ive tried every single combination of this stuff, but the best it resolves to is: <script src="/ScirraNew/js/googleAnalytics.js"></script>. My site is in the ScirraNew folder, but it needs to resolve to ../js/Googleanalytics.js!
<link id="Link1" runat="server" href="~/js/googleAnalytics.js" /> this works fine, but renders as a link tag, sigh :(
@Tom Gullen - Are you sure you are using ResolveClientUrl (not ResolveUrl). The believe the former creates the ../ style path, whereas the later creates a root-relative path. I am going to test right now to be sure though.

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.