Course Overview
Take the Scala you already write to the browser. This course covers Scala.js end to end: setting up a cross-built project, sharing model and validation code between server and client, calling JavaScript libraries with real types, and shipping an optimised bundle.
It is aimed at teams who want one language and one shared domain model across the whole stack, rather than maintaining the same types twice in two languages that never quite agree.
Who should attend
Scala teams who own a web front end and are tired of duplicating their domain model in TypeScript, and Scala developers who want to understand what compiling to JavaScript actually costs before committing to it. Some familiarity with the browser platform is assumed; deep JavaScript experience is not.
What you'll learn
- Set up a cross-built sbt project with shared, server and client modules
- Share domain models, validation and serialisation between the JVM and the browser
- Understand where Scala.js semantics deliberately differ from the JVM, and why
- Call JavaScript libraries with statically typed facades, and expose Scala APIs back to JavaScript
- Build user interfaces with the current Scala.js UI libraries
- Test cross-built code and ship an optimised production bundle
Course Prerequisites
It is expected that participants are familiar with html/css and preferably have a basic understanding of the scala language.
Outline
Scala.js exists to solve a specific and expensive problem: the same domain model written twice, once on the server and once in the browser, drifting apart one deployment at a time. Compile Scala to JavaScript and the shared model becomes a single source that both sides are checked against.
This course is about making that work in practice. We set up a cross-built project properly, share the code that is genuinely shareable, and are honest about the code that is not. We also go beneath the abstraction: what the Scala.js linker actually emits, why the optimised output is so much smaller than you would expect, and where the semantics deliberately part company with the JVM.
If you are new to Scala itself, start with Core Scala 3 Masterclass.
Introduction to Scala.js
- Introduce Scala.js and the problem it was built to solve
- Appreciate the history: why a Scala-to-JavaScript compiler was worth building
- Understand the linker and what it emits
- Discuss whole-program optimisation and why dead code elimination matters so much here
- Compare the fastLink and fullLink modes and their place in a workflow
- Contrast Scala.js with the alternatives: TypeScript, Kotlin/JS and ScalaJS-free architectures
- Discuss honestly when not to use Scala.js
Project Setup
- Set up a multi-project sbt build with shared, JVM and JS modules
- Understand cross-building and how one source tree serves two platforms
- Configure the sbt-scalajs plugin
- Manage JavaScript dependencies with scalajs-bundler or an external bundler
- Integrate with Vite for a modern development experience
- Configure source maps so browser stack traces point at Scala
- Structure a repository that stays navigable as the project grows
Sharing Code Between Client and Server
- Understand isomorphic code and what genuinely belongs in a shared module
- Share domain models and validation rules
- Serialise across the boundary with a cross-compiled library such as uPickle or circe
- Define a shared API contract and call it with type safety in both directions
- Discuss what cannot be shared, and how to keep the boundary honest
- Handle cross-platform differences in date, time and locale handling
Scala.js versus the JVM
- Understand where Scala.js semantics deliberately differ from the JVM
- Appreciate the absence of reflection, and the consequences for libraries
- Discuss numeric differences, particularly
Longand floating point - Understand why blocking does not exist, and what replaces it
- Explore the supported subset of the Java library
- Work with concurrency in a single-threaded runtime, using
Futureand the event loop - Inspect the generated output to understand what the compiler produced
JavaScript Interoperability
- Understand Scala and JavaScript type correspondence
- Call JavaScript with static types: primitives, functions and objects
- Define traits as facades for JavaScript APIs
- Annotate facades with @js.native and
@JSGlobal - Use js.Dynamic to call JavaScript without a facade, and appreciate what you give up
- Convert between Scala and JavaScript collections
- Expose Scala APIs to JavaScript with
@JSExport - Consume npm packages from Scala.js
- Discuss the state of ScalablyTyped for generating facades from TypeScript definitions
Working with the Browser
- Manipulate the DOM from Scala using the
scalajs-dombindings - Handle events in a typed way
- Make HTTP calls with the fetch API
- Understand the event loop as it applies to Scala
Future - Build user interfaces with a Scala.js UI library such as Laminar or Slinky
- Contrast wrapping a JavaScript framework with using a Scala-native library
- Manage application state in a functional style
Testing and Delivery
- Test cross-built code with ScalaTest or munit on both platforms
- Run JS-side tests in a headless browser or Node.js
- Debug through source maps in browser developer tools
- Optimise the production bundle and understand its size characteristics
- Discuss code splitting for large applications
- Integrate the build into a CI pipeline
Frequently asked questions
Why compile Scala to JavaScript rather than write TypeScript?
Because the model stops being defined twice. When the domain types, validation rules and serialisation live in shared code, a change on the server cannot silently disagree with the client; it fails to compile. That is the whole argument, and the course spends time on where it does and does not pay off.
Do I need to be a JavaScript developer?
No. You need to know Scala and be comfortable with HTML and CSS. We teach the JavaScript platform where it shows through, particularly the event loop, the DOM and the module system, because you cannot interoperate with something you cannot see.
How much Scala do I need?
Working knowledge. If your team is new to the language, take Core Scala 3 Masterclass first. This course spends its time on Scala.js and the browser, not on the language itself.
Does everything from the JVM work?
No, and the differences matter. Reflection is out, numeric behaviour differs in places, blocking does not exist, and the Java library surface available to you is a subset. We cover these deliberately rather than letting you discover them during a migration.
Which UI approach do you teach?
We cover the current Scala.js UI options and the trade-off between wrapping a JavaScript framework and using a Scala-native library. Private courses can concentrate on whichever your team has chosen, so tell us when you book.
How hands-on is the course?
Lab work runs throughout, building a single cross-built application rather than isolated examples, since the point of Scala.js is what happens across the client and server boundary.
How long is the Scala.js for Scala Developers course?
2 days on-site or 3 days online. Sessions can run on consecutive days or be spread out to fit your team's schedule.
What are the prerequisites?
It is expected that participants are familiar with html/css and preferably have a basic understanding of the scala language.
How large are the groups?
Deliberately small so the trainer can adapt to every participant: at most 10 on-site and 7 online.
In which languages can the course be delivered?
English, French or Dutch.