I have a widget (some html code) that should be loadable on different Websites (which are not under my control) but the widget is hosted on my server.
Until now I had a PHP Script producing javascript code looking someting like this:
document.write('<div> ... some more dynamic html ...</div>');
which then could be loaded on any html page with the tag.
Now I’m planing a redesign and want to do the PHP part with server-side javascript. Do I still need to output document.write() or is there a more clever way now days, as we have handlebarjs, node.js etc. Also: I’d be interested I those new fancy autoupdate features frameworks like meteor or derby provide…
(I wanted to use meteor (meteor.com) to do the job but meteor outputs full html pages and I do not need a whole page)
Thank you for your help/sugestions
You have to output something that will cause the content to be rendered on the client.
The client side code will be more or less independent of the server side code (although you might get some cross-over if you start using tools such as mojito.
node.js won’t help with what you output, since it is a server and the JS to modify the page has to run in the browser.
You could use a template language like handlebarjs. You could use a library to aid DOM manipulation. The problems are that the more code you load (libraries included), the more likely you are to clash with something used by the third party websites upon which your code is embedded, and the heavier you make their pages (and large increases in page weight are a particularly poor idea for secondary content).