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 ../?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456

1 Answers1

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>
Chris Stillwell
  • 10,266
  • 10
  • 67
  • 77
dana
  • 17,267
  • 6
  • 64
  • 88
  • 6
    You probably only need ResolveUrl(), as ResolveClientUrl creates the whole URL, rather than just the relative path. – Forgotten Semicolon Mar 06 '11 at 00:45
  • Thanks, ive tried every single combination of this stuff, but the best it resolves to is: . My site is in the ScirraNew folder, but it needs to resolve to ../js/Googleanalytics.js! – Tom Gullen Mar 06 '11 at 00:50
  • this works fine, but renders as a link tag, sigh :( – Tom Gullen Mar 06 '11 at 00:53
  • @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. – dana Mar 06 '11 at 00:56