Ideas for automatic dynamic web pages

27 views
Skip to first unread message

Wout Mertens

unread,
Mar 31, 2012, 6:03:21 AM3/31/12
to coff...@googlegroups.com
So I was thinking about how cool Coffee[kc]up is, making it possible to render a template server-side or client-side on demand, without any changes to the template, and then I thought that the tag function definitions could be changed at will.

This made me think about automatically doing AJAX this way. I'd like to lay out some ideas and start a discussion.

The reason I think this is cool is because then you can make highly interactive pages without having to write all the AJAX scaffolding, and getting a server-side rendered version for search engines for free. Plus it would all be written in CoffeeScript and automatically converted into optimized Javascript and HTML.

So instead of '<html>…<body>the body…' you would produce '<html>…<body><script>document.write("the body…");…'. This could be stored as static minified HTML which would get etag handling for caching etc so that on subsequent page loads the browser would only need to get the changed data, speeding up the client feel and lessening the load on the server.

So for example, you could change the definition of e.g. body() at template compile time so that instead of getting HTML you get a function that gets executed by the browser and writes the HTML to the real body. This function could then use AJAX calls to get the values needed to compile the template instead of providing them at compile time.

Another possibility would be a wrapper function, e.g. ajaxify() that you call on the dynamic page contents and that replaces "ajaxify wrapped_tag…" with "<script>get_data(function (data){function wrapped_tag(data){…}; document.write(wrapped_tag(data));})</script>" where the get_data(callback) asynchronously or synchronously provides the template data, either defined higher up or fetched via ajax.

Depending on wether you want one-shot or continuous updates, the ajaxify function would write different scripts. There could be coffeecup plugins for polling REST data or using realtime ShareJS documents etc, all without changing your page or writing specific browser-side code.

So in the end, you would just once write a template with dynamic content and give it to the middleware which either renders it server side or provides everything for quick client-side updates, all without you lifting a finger.

All this is (probably) possible because coffee[kc]up is coffeescript. So awesome :)

What do you think? Will this work?

Wout.

Reply all
Reply to author
Forward
0 new messages