1

Currently i have the following html-index-file:

I have to set the base-url by javascript (it depends on the url) i can't write it hardcoded to the index.html.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <script>
            document.write("<base href='http://localhost:4200/test/' />");
        </script>
    </head>
    <body>
        <script type="text/javascript" src="runtime.js"></script>
    </body>
</html>

And this is working good!

But if i have a look on the network tab i can see that the script "runtime.js" is triggered twice.

"localhost:4200/runtime.js" -> 404 
"localhost:4200/test/runtime.js" -> 200

So is there a possibility to interrupt the first loading?

Here is a fiddle for that: https://jsfiddle.net/tbaqovj5/

Flo
  • 1,179
  • 3
  • 15
  • 43
  • Whatever you're doing sounds like a bad plan. `document.write` is never to be used in professional work. I think the second loading is some kind of browser optimization, but I can't be sure. You should really rethink this and maybe use HTML template if you need to write in the HTML before any execution. – Tomáš Zato Aug 27 '19 at 09:35

0 Answers0