In recent days i did some study on javascript and had some interesting thought.
I wrote a lightweight javascript library (built on prototype, I call it Jscp - javascript clientp page)
to implement this. With the library, the work of rendering page template with data
run on client-side, that is, in web browser programs.
Traditional service model:
1. client --- send request ---> server
2. client(wait) server (working for request, get result data)
3. client(wait) server (rendering page template with data)
4. client <--- recv result page --- server
With jscp, the model becomes:
1. client --- send request ---> server
2. client <--- recv page template --- server (could be cached for use many times)
3. client --- send request ---> server
4. client(wait) server (working for request, get result data)
5. client <--- recv result data --- server (data use JSON format)
6. client (rendering page template with data) server
I think this model provide cleaner interface between server and client.
The code running on server focus on generate correct result data,
data be sent in standard JSON format, and the code to display it
run on client-side (though still be deployed on server).
I don't know if there is some existing js library has such feature,
i tried and didn't find.
For simple example comparision:
with PHP, in .php files you write:
... <? for i=0; i<3; ++i { ?>
... <? echo res[i].'/r/n' ?>
... <? } ?>
with Ruby on Rails, in .rhtml files you write:
... <% 1.to(3) do { |i| %>
... <%= @res[i] %>
... <% } %>
with Jscp, in .htm files your write: (use javascript)
... <%INC ../layout_header.htm %>
... <% var r=_RENDER_DATA; %>
... <% for i=0; i<3; ++i { %>
... <%= r.res[i] %>
... <% } %>
... <%INC ../layout_foot.htm %>
By moving the last rendering work from server-side to browser-side, some effects are easy to implemented, such as local pagination, local table sorting, etc. Jscp is not conflict with other Ajax technologies, since it is on the bottom layer of them.
I registered JSCP as a project on sourceforge.net, it can be visited from the following URL: