Attempting to build an application using the combination of playframework
, scala
, and Angular JS
, I aimed to create a web app that functioned seamlessly whether JavaScript was enabled or disabled in the browser. This requirement is common when developing a public site that needs to be user-friendly as well as search engine optimized for Google indexing.
The end result was roughly 50% of the code written in JavaScript
, with separate folders named "controller" - one housing Scala code, and the other containing JS code (due to AngularJS utilizing the controller concept). Additionally, a new scala-controller had to be implemented to handle json
responses instead of html
, solely for the JS code's Ajax calls. This process felt overly complex and labor-intensive.
In terms of the playframework
templates, combining Scala
with JavaScript
presented challenges in passing parameters between the two languages. Various tricks were employed to manage this interaction depending on whether JS was active or inactive. However, these workarounds made the template less intuitive and scalable; potentially leading to duplicated templates for different scenarios.
As the volume of JS code increased, approaching 60% of the total, the idea of maintaining dual applications—one for users and another tailored for Google—seemed inevitable. While data duplication could be avoided by referencing the same database entities, discrepancies in data formatting (likely json-based) may arise. Furthermore, considering utilizing NoSQL databases like MongoDB for their compatibility with JS-native operations.
This raises the question: why not leverage JS for handling basic functions such as request-response, page composition, and layouts entirely? By having a server-side JS controller generate templates, the need to switch between languages could be eliminated, boosting productivity and efficiency.
Question:
Are there any recommended practices or suggestions to streamline this setup? While steering clear of consolidating all functionalities under NodeJS
for both server and client-side scripting, it's crucial to prioritize productivity and business requirements.
For reference, here is an example showcasing the extent of JS code required for AngularJS controllers: https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/angularjs/js
Consider the complexity of managing PlayFramework controllers alongside this for HTML and AJAX interactions, highlighting the intricate mix of Scala/playframework templates with JavaScript elements.