Alternatives like TeaVM let you code Java in the browser but it compiles quickly to compact JavaScript. This way you can get the best of both worlds. A typed language, full-stack refactorings, and the security of the browser JS VM.
TeaVM Website: https://teavm.org/
Tutorial in Java Magazine: https://blogs.oracle.com/javamagazine/java-in-the-browser-wi...