Isomorphic Web Applications with Scala and ScalaJs20 Mar 2016
What is an isomorphic web application?
An isomorphism is a mathematical term used to indicate that two things, from an high level perspective, are essentialy the same.
In the context of web applications it means that we have code shared between the front-end and the back-end.
It also means that we can execute the client side code on the server.
With no doubt a more clear and less scary term is Universal web application.
Why is server side rendering useful?
It’s useful for a number of reasons:
- SEO: Having your MVC framework generate the views client side make difficult, if not impossibile, for crawlers to index your application. That’s why a number of libraries, such as React, can easily render views server side.
Fetch as Google your SPA to see the result.
What is ScalaJs?
undefined is not a functionerrors discovered at runtime, maybe in a production environment.
You now have strong type checking and lots of errors will be discovered at compile time. Your code will be more robust and your cortisol level will be optimal.
You have more expressive, modular and reusable code.
When you start building large (10k+ LOC) and complex Single Page Applications and your codebase grows rapidly, it’s better to have a more expressive language in order to express the same concept with fewer lines of code (arrow functions in ES6 make your keyboard last longer).
Less code less bugs
Same language for the server and the client.
It’s great to know many programming languages but for a web application, maybe with offline support, it’s great using only one. This way you reduce code duplication, for example form validation, currency formatting and so on, sharing the business logic code easily with the server. This way you reduce your cognitive load and the probability of making stupid mistakes such as writing
You also get better tooling and better IDE support.
You can navigate easily your code and refactoring is safer and so easier.
["10", "10", "10", "10"].map(parseInt);
Isomorphic web app with ScalaJs
With ScalaJs you can literally be a full stack Scala engineer and also target the mobile world. You can write your React Native mobile application in Scala with React native interface, compile your code with ScalaJs and deploy it.
Until next time