I don't know where I got the idea before but a year ago I wrote this in php:
<script type="text/javascript" src="http://www.mydomain.com/getmarkers.php"></script>
Now I'm ready to convert this website to an ASP.NET MVC website and I'm wondering what the best way is to convert this into something more 'normal?'.
The options I could think about where:
- Custom HttpHandler for .js files
- Keep using the script tag but with a custom route to an action
- Modify the javascript to load the serverside data using an ajax call
What the getmarkers.php currently does is generate javascript to add markers to a google map. The benefit of referencing the php inside the script tag is that
- It's never cached, the markers are always up to date (I know there are alternatives)
- It keeps my html clear of any javascript
- Very easy to add/remove certain fields for the generated markers
An example of what is being generated :
infoWindows[0] = new google.maps.InfoWindow({
content: '<div style="width:250px;color:#000;">...html content for this specific marker...</div>'
});
google.maps.event.addListener(markers[0], 'click', function() {
infoWindows[0].open(map, markers[0]);
});
What changes is the index (0 in this example) and the content of the html.
Question
1. What solution do you think fits best
2. Is it bad to reference a script by calling a serverside 'file'.