Serving the map page as text/html
Posted by jamie on 05 Jul 2011 in Notes
Due to a recent change in Google's map JS API (who knows what that change is), I've had to change the map page to be served as text/html rather than application/xhtml+xml. Here's the comment that I put in the HTML source on the eXist version of the site:
July 05/2011, Jamie Nay:
This page is served as text/html rather than application/xhtml+xml because the Google Maps JS API uses document.write to write elements to the DOM, which isn't supported by XHTML.
Google knows about this issue ( see http://code.google.com/p/gmaps-api-issues/issues/detail?id=530 and http://code.google.com/p/gmaps-api-issues/issues/detail?id=2820 ) but won't fix it. Instead they suggest a
workaround (better known as a hack): passing a callback function when loading the API script.
Unfortunately, neither this:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&callback=initialize"></script>
Nor this:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('maps', '3', {'other_params': 'sensor=false', 'callback': initialize});
</script>
Seems to work; I've tried both approaches (loading the API directly and using google.load). The bottom line seems to be that, no matter what workaround you try, you just can't load the API properly while serving your
content as application/xhtml+xml.
Prior to early July/late June 2011, the API was being loaded successfully because I had put in a document.write clone script that I found at: http://weston.ruter.net/projects/xhtml-document-write/
That script added document.write support to pages served as application/xhtml+xml. However, due to what I can only assume is a recent change in the Google API, this fix no longer works and the map does not display correctly under any circumstances when serving with the xhtml mime type. So, the only feasible solution in terms of time and effort spent is to serve this map page as text/html. If there's a pressing need to serve as application/xhtml+xml in the future then this issue needs to be resolved. For now, however, text/html is doing the job.