Isomorphic code
Isomorphic code refers to application code that runs seamlessly in both client and server environments. To achieve this in Aurelia:
Avoid Environment-Specific Globals
Instead of directly accessing browser-specific globals like document
or window
, use Aurelia's PAL:
Platform Abstraction Layer (PAL)
Aurelia's PAL provides a consistent API for DOM manipulation and other platform-specific tasks, ensuring your code remains environment-agnostic.
Example
Without PAL (Not Isomorphic):
With PAL (Isomorphic):
Best Practices
Use PAL for DOM Operations: Always use
aurelia-pal
for any DOM-related tasks.Conditional Logic: If certain code should only run on the client or server, use environment checks to prevent execution in the other environment.
Last updated
Was this helpful?