Compiling JavaScript on Serverside With Scala and ScalaJS
Since my experience with the JavaScript world and exploration of ScalaJS I felt compelled to move from Node and Grunt and try to fully utilize Scala for both front and back.
I reached a goal with Scala Stack, a concept of creating all web content on serverside using only Scala code. The concept is extended to keep everything in code including configuration to be fully testable.
Future of Internet
If we try to look into the future of internet, I think we see two strong forces: Market and AI.
How will they alter the internet we use today?
- Market want to extract most of its users and want to create webpages which are fully personalized in an effort to guide the users to their goals. Sites are personlizing the pages by user settings but why shouldn't all content including color and shape be adopted to the user in a effort to please the user as much as possible?
- AI and ML is on the uprising and if the server is thinking for itself it could create whatever as a response.
Obvious Advantages
My main purpose was to skip the JavaScript world but it moved on to something much larger. If all code is shared there are quite a few advantages
- Single, isomorphic source which ease work and can share logic
- Share data by keeping it in code. For instance languages could be defined with a Enum type
- Fully testable code
- No JavaScript package manager like NPM or WebPack
- No pre processor like Gulp or Grunt
Risks
There are some traps though
- Security, some code should not be shared
- Long term effects, demands a experienced architect
- Shared code needs to be ScalaJS compatible and cannot use backend dependencies since it's compiled and used on frontend
Scala Stack
I've made three implementations using Google Flexible Environment. Implemented in native JavaScript, jQuery and AngularJS.
Goal is to keep everything in code and to avoid configuration, annotations and settings in Strings.
By only using Scala on serverside, it produce HTML, CSS and JavaScript which is all components for a webpage.
Map of Scala Stack |
Servlet Compiler
Scala Stack is using a Servlet compiler with different logging:
- https://github.com/AIMMOTH/scala-js-compiler
- Jetty https://github.com/AIMMOTH/scalajs-compiler-jetty
Moi
I discovered C and JavaScript in school 98-99 and have coded since.
As an individual the first problem is to be creative within the little time that is left of work and social life. Keeping goals through discipline and understand how to be efficient was fundamental. 2012 I discovered Google App Engine and within a single JSP-file kept HTML, CSS, JavaScript and Java with a database connection, I was hooked! This was all I needed to create a site. The PaaS handled publication, dashboard, configuration of services, hosting, logging and have a big library of API for the basic operation, which meant I could spend time on coding.
Mixing code with a subject are my main interests and when creating my first sites I understood that it's impossible to create content driven sites by myself. The solution was to give the users tools to modify the site as they witched and, as a community, create the site they wanted in a democratic way.
Inga kommentarer:
Skicka en kommentar