0

I am use to working with MVC and previously Web Forms of asp.net so with those View Engines to Server ... I never had to worry about when I worked with visual studio on local computer to publishing the website to servers.

However, the way I started building websites is with HTML5 calling up Web Api

Basically so that I can easily work locally and promote the code i end up doing this "hack" is there a better way?

As you see if not detecting localhost i have it add in DOCCCO

Its a Web Api project in which I use plan HTML files with jquery ajax calls ..

locally it renders to localhost:455434/whatever.html
server then is servername/DOCCCO/whatever.html

Thus the SERVERNAME is = localhost:port , but the project name is getting injected / appended as it has to on the server as there are many projects.

So what are my options with more barebones HTML5 ?
1. fix localhost:port to always have localhost:port/DOCCCO , how? 2. fix web api Webapiconfig.cs or routeconfig.cs ???

<script>
            if (document.location.hostname === "localhost") {
                document.write('<script src="/Scripts/jquery-2.1.4.min.js"><\/script>');
                document.write('<script src="/Scripts/jquery.tablesorter.min.js"><\/script>');

                document.write('<script src="/Scripts/app.js"/><\/script>');
                document.write('<script src="/Scripts/flexdropdown.js"/><\/script>');

            }
            else {
                document.write('<script src="/DOCCCO/Scripts/jquery-2.1.4.min.js"><\/script>');
                document.write('<script src="/DOCCCO/Scripts/jquery.tablesorter.min.js"><\/script>');

                document.write('<script src="/DOCCCO/Scripts/app.js"><\/script>');
                document.write('<script src="/DOCCCO/Scripts/flexdropdown.js"/><\/script>');

            }
        </script>
  • If you use a build tool or something to compile all of your scripts you won't need to worry about injecting a ton of scripts. – Mark C. Feb 03 '16 at 19:45
  • true, so what exactly would you propose with a web api 2 project with html files and css and javascript files? msbuild ? Any links to examples and options would be appreciated thx –  Feb 03 '16 at 20:52
  • Well, even bundling could do this for you as well. – Mark C. Feb 03 '16 at 20:56
  • I think automatic bundling and minification are features of MVC. You could create an MVC project even if it is just serving a SPA (single-page application) and make use of these features. http://www.asp.net/mvc/overview/performance/bundling-and-minification – rom99 Feb 04 '16 at 10:28

1 Answers1

1

You might want to use relative rather than absolute URLs, see for example this answer.

That means defining the URLs without the leading slash, e.g. "Scripts/app.js" instead of "/Scripts/app.js"

Community
  • 1
  • 1
rom99
  • 709
  • 4
  • 14