I have a mean-stack site. My source code uses office.js , we need to add history.js to provide html5mode . As a result, opening https://localhost:3000/home in the browser always saves https://localhost:3000/home (i.e. it doesnβt add # thanks to history.js ). In index.html we have:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script> <script src="https://cdn.rawgit.com/devote/HTML5-History-API/master/history.js"></script>
Now I want to download history.js based on some conditions only. People suggested I use appendChild(aScript) . Therefore, firstly, I just try the following code without any conditions:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script> <script> var newScript = document.createElement('script'); newScript.src = 'https://cdn.rawgit.com/devote/HTML5-History-API/master/history.js'; document.head.appendChild(newScript); console.log(window.location.href) </script> <script>console.log("here")</script>
My tests show that the first time you boot https://localhost:3000/home will not change. However, if I update the browser, it may change to https://localhost:3000/#/home .
This means that adding a script does not perform exactly the same as a direct link.
Does anyone know why?
Otherwise, is there any other way to conditionally load the link? What I want to achieve is to always load history.js except for one specific page.
PS: window.location.href always displayed before here .
source share