Frontend
·1 min read·↗

Angular and Domino: A Powerful Combo for Server-Side Rendering.

Main cover illustration for article: Angular and Domino: A Powerful Combo for Server-Side Rendering.
Summarize with AI:

If you are using Angular and need to access DOM with SSR, then use the domino package.

Domino provides support for the DOM API and also CSS for querySelector(), querySelectorAll(), and matches().

Install the domino package from your terminal.

npm install domino --save

Add angular universal in your app. ng add @nguniversal/express-engine Edit the server.ts file and add the following lines. To configure it, create a "document" object and a "window" as global.

const domino = require('domino');
const fs = require('fs');
const path = require('path');
 
// Use the browser index.html as a template for the mock window
const template = fs
  .readFileSync(path.join(join(process.cwd(), 'dist/yourprojectname/browser'), 'index.html'))
  .toString();
 
// Shim for the global window and document objects.
const window = domino.createWindow(template);
global['window'] = window;
global['document'] = window.document;

If you want to copy and paste, please change the project name.

Keep in mind that change for server-side render, the build command is built:ssr and needs to publish the browser directory.

npm run build:ssr
dist/yourprojectname/browser
Part of the Frontend Series

Modern frontend development — Angular, React, TypeScript, accessibility, and performance.

View Entire Series

Related Articles

Share this article

If you found this guide helpful, consider sharing it with your team or fellow developers.


Real Software. Real Lessons.

I share the lessons I learned the hard way, so you can either avoid them or be ready when they happen.

User avatar
User avatar
User avatar
User avatar
+13K

Join 13,800+ developers and readers.

No spam ever. Unsubscribe at any time.