I am currently creating a Javascript library that can be used to easily create embedded media based on the URL of a media file, and then be managed using Javascript methods and events (think of a Flash / Silverlight JW player ).
Of course, I could just dig out all the html tags from the Javascript library and send them to the browser:
function player(url) { document.write('<object type="foo"><param name="something" value="bar">' + <param name="source" value=" + url + '/></object>'); }
But I think this is a very ugly practice that tends to create unmanaged code that cannot be read when you review it a few weeks later.
So the template solution seems to be suitable for this. I was looking for EJS because it loads templates using AJAX, so you can manage your templates in a separate file and not directly on the HTML page.
There's one gotcha with this: my library should be completely cross-domain: the library itself can be located on foo.com, and the service site can be located on bar.com. Therefore, if bar.com wants to add a media player using the library, it needs to make an AJAX call to the template located on foo.com, which will not work due to policies of the same origin in browsers.
AFAIK, there is no library that uses something like JSONP to read and write templates to work around this problem.
Can someone point me to a solution to this problem?
source share