Get rid of hard-coding the context path of web apps in external JavaScript files
问题 I have several WebSockets endpoints such as, wss://localhost:8181/ContextPath/Push All of such endpoint URLs are hard-coded in separate, external JavaScript files ( .js ). These JavaScript files are included in respective XHTML files as and when required. The host name and the context path should be evaluated programmatically instead of hard-coding all over the place where they are required. The host name ( localhost:8181 ) can be obtained in JavaScript using document.location.host but there