I tried to write an application on playframework
+ scala
+ Angular JS
.
The purpose was to create an web app that would work either good when JavaScript is OFF or ON in the browser. This is usual requirement when one writes Public Site (which should be good for people and for Google that would index it)
So I ended up with ~50% code written in JavaScript
, having two(2) folders named "controller" - one for Scala
code, one for JS
code (since AngularJS uses controller concept as well).
Also, since JS
code is supposed to use Ajax
calls, I had to create one more scala-controller that returns json
, but not html
back to client's request. And.. this all I do not like. This seems as too much effort.
On playframework
template side, I should think how to combine Scala
with JavaScript
, passing parameters from one language to another. Using some tricks like showing that when JS would be processed, showing that when it is supposed to be off.
This all makes my template less understanable, and one day, when I have huge code base, I may come up with a solution to duplicate my templates as well (js templates + scala templates) - to use proper template when JS
is off/on. Then amount of JS code could rise up to 60%..
And then it seems that I'm going to duplicate everything, like having two different application - for Google and for people. What would be common (only) is my data themselves in my database, I have not to duplicate data. But.. there we might have a different issue with a format of that data (and most likely would be json-based [because I do not wasting processor time to do table-object transformation], but not table based - NoSQL.. then again we come to JS like DB - like to MongoDB), and JS
works very good with Json, natively.
Then question, why not use 100% of JS
for simple things like: request-response, forming a page, layouts. Server side JS
controller could form my templates - then I do not need to switch from one language to another and be even more productive in this sense.
Question:
Do you have any suggestions? Best practices about this? I'm not that guy who want to end up using NodeJS
to useJavaScript
as ONE languages for everything - for server and client. But let's speak about productivity and business needs.
There is an example (not mine) of AnjularJS controllers, how much JS I have to write: https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/angularjs/js
and just imagine that I have to keep PlayFramework controllers along with that - for HTML and AJAX calls, mixing things in scala/playframework templates with JavaScript.