1- A a starter. document.write
will replace the whole DOM with your list, therefore, I suggest appending the list to an html element.
2- To improve performance, try to have less function call to reduce overhead. Option 1: prepare the html and write it in one string, then append that string. E.g.
var lang = "<ul><li>stuff...</li><li>other stuff....</li></ul>";
Or, for readability,
lang = "<ul>";
lang = "<li><a href=\"http://localhost:8888/en/" + location.pathname + "\">English</a></li>";
lang = "<li><a href=\"http://localhost:8888/fr/" + location.pathname + "\">French</a></li>";
lang = "</ul>";
Then
$("#change_lang").html(lang);//change_lang is a div <div id="change_lang"> that you have prepared to put the links inside.
3- Maybe you can load the html from your server directly, without having JS to print it on screen for you. Put it in .html page (I'm not sure about your page structure, therefore, I cannot know why this approach might not be suitable for you) but loading html directly without waiting for JS and JQuery to load will make display much faster.
<ul>
<li><a href="http://localhost:8888/en/yoursite.html">English</a></li>
<li><a href="http://localhost:8888/fr/yoursite.html">French</a></li>
</ul>
4- Also try to put your JS code in separate files, and then minify them to reduce size and hence loading time. Having JS in separate files allows the browser to cache them and eliminate the need to load them every time. Search for PageSpeed to show you various ways to improve your site performance.